-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
.whenContentError(cause -> closeIfConnected(origin, connection)) | ||
.whenCompleted(() -> returnIfConnected(origin, connection)) | ||
.apply(); | ||
}); |
There was a problem hiding this comment.
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!
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/ As ultimate producers of connections, unsubscriptions must be dealt with in the connection pool, and in |
connectionRef
variable from Transport class.
connectionRef
variable from Transport class.
Forward port the fix in #326 to master