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

Changing catch to finally in PipeDuplexRequestBody.forConsume prevents long-lived streaming connections #31

Closed
kohenkatz opened this issue Mar 16, 2023 · 0 comments · Fixed by #36

Comments

@kohenkatz
Copy link
Contributor

This change in #22 prevents the stream from staying open for long-lived connections.
For example, when handling user chat input, version 0.1.2 keeps the connection open while 0.1.3 and newer close the connection after a message is sent because the buffer is "temporarily" out of data until the user types the next message.

    fun forConsume(buffer: Buffer) {
        try {
            if (bufferedSink.isOpen) {
                bufferedSink.writeAll(buffer)
                bufferedSink.flush()
            }
-        } catch (e: Throwable) {
+        } finally {
            close()
        }
    }

I think that what should actually be here is something like this:

    fun forConsume(buffer: Buffer) {
        try {
            if (bufferedSink.isOpen) {
                bufferedSink.writeAll(buffer)
                bufferedSink.flush()
            }
+       } catch (e: Throwable) {
            close()
+           throw e;
        }
    }
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 a pull request may close this issue.

1 participant