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

Okhttp Websocket client 'closeReason' is not completed when websocket fails #1363

Closed
varahash opened this issue Sep 27, 2019 · 8 comments
Closed
Assignees
Labels

Comments

@varahash
Copy link

Ktor Version and Engine Used (client or server and name)
io.ktor:ktor-client-okhttp:1.2.4

Describe the bug
The 'closeReason' at line https://github.com/ktorio/ktor/blob/1.2.4/ktor-client/ktor-client-okhttp/jvm/src/io/ktor/client/engine/okhttp/OkHttpWebsocketSession.kt#L48
must be completed with 'null' value when websocket fails here: https://github.com/ktorio/ktor/blob/1.2.4/ktor-client/ktor-client-okhttp/jvm/src/io/ktor/client/engine/okhttp/OkHttpWebsocketSession.kt#L93

@varahash varahash added the bug label Sep 27, 2019
@e5l e5l self-assigned this Sep 27, 2019
@cy6erGn0m
Copy link
Contributor

It should complete exceptionally, null makes no sense

@varahash
Copy link
Author

Then you should update doc as well:

It could be null if a session is terminated with no close reason (for example due to connection failure).

https://github.com/ktorio/ktor/blob/1.2.4/ktor-http/ktor-http-cio/common/src/io/ktor/http/cio/websocket/DefaultWebSocketSession.kt#L24-L26

@dmitrievanthony
Copy link
Contributor

Hi @varahash, @cy6erGn0m,

the only issue I found is that OkHttp actually does not complete close reason in case of failure. I fixed it in the PR above.

@varahash
Copy link
Author

Why documentation says that closeReason can completes with null and as example provides connection failure?

/**
* A close reason for this session. It could be `null` if a session is terminated with no close reason
* (for example due to connection failure).
*/
val closeReason: Deferred<CloseReason?>

How CIO implementation completes closeReason, exceptionally or with null?
If exceptionally, what is real case for closeReason to be null?

@dmitrievanthony
Copy link
Contributor

@varahash, the documentation says so because in some corner cases closeReason could be null and users should take this into account. As far as I remember, particularly CIO completes it with null.

@varahash
Copy link
Author

If so, maybe it is better to make OkHttp version match CIO implementation.

@dmitrievanthony
Copy link
Contributor

Well, if we are talking from a design perspective I think it would be more informative to pass exception in CIO.

@dmitrievanthony
Copy link
Contributor

I merged the corresponding PR, so the fix is in master now. Feel free to reopen the issue if you have additional comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants