Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mutable state (connectionRef) from Transport class. #329

Merged
merged 2 commits into from
Nov 2, 2018

Conversation

taer
Copy link
Contributor

@taer taer commented Oct 25, 2018

Forward port the fix in #326 to master

.whenContentError(cause -> closeIfConnected(origin, connection))
.whenCompleted(() -> returnIfConnected(origin, connection))
.apply();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @taer

The observable should be constructed like this:

            public Observable<LiveHttpResponse> response() {
                return connection.flatMap(connection -> {
                    Observable<LiveHttpResponse> responseObservable = connection.write(request)
                            .map(response -> addOriginId(originId, response));

                    return ResponseEventListener.from(responseObservable)
                            .whenCancelled(() -> closeIfConnected(origin, connection))
                            .whenResponseError(cause -> closeIfConnected(origin, connection))
                            .whenContentError(cause -> closeIfConnected(origin, connection))
                            .whenCompleted(() -> returnIfConnected(origin, connection))
                            .apply();
                });
            }

The ResponseEventListener.from takes a response observable and decorates it with event listeners triggering at relevant points of the response lifecycle. It takes into account both response observable and its associated body byte stream. The apply method returns a new Observable<LiveHttpResponse> that should be returned for the downstream observers.

Also, I have pushed this to your branch. Please pull the lates changes to have a look!

@mikkokar
Copy link
Contributor

mikkokar commented Nov 2, 2018

Hi @taer. This is a good PR even if it doesn't actually fix the leak. Therefore I am going to rename the PR title accordingly and merge.

For the record, the root cause for the connection leak is lack of cancel/unsubscribehandling for connection observables. More specifically, Transport class handles cancellations for response observables, which only works after a connection event is published from the connection observable. The cancellation therefore doesn't have any effect when subscriber (connection) is pending.

As ultimate producers of connections, unsubscriptions must be dealt with in the connection pool, and in NettyConnectionFactory.

@mikkokar mikkokar changed the title Forward port the potential leak fix to master Remove mutable connectionRef variable from Transport class. Nov 2, 2018
@mikkokar mikkokar changed the title Remove mutable connectionRef variable from Transport class. Remove mutable state (connectionRef) from Transport class. Nov 2, 2018
@mikkokar mikkokar merged commit f518a89 into ExpediaGroup:master Nov 2, 2018
@taer taer deleted the masterLeak branch November 7, 2018 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants