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

Improvements in HTTPServerResponse.write() methods #84

Merged
merged 1 commit into from
Sep 5, 2018

Conversation

pushkarnk
Copy link
Contributor

This commit includes a fix for an embarrasing bug - we wrote to the response buffer only if it was nil, after allocating it. This meant, for N consecutive writes to it, only the first would be honored and N-1 would be ignored. This change also eagerly allocates the response buffer with an initial size of 2000, just like KituraNet does it. We don't keep the buffer as an optional anymore. We allocate it in the initializer because we are pretty sure that the HTTPServerResponse initializer always runs on an event loop.

@ianpartridge
Copy link
Contributor

Test please :-)

This commit includes a fix for an embarrasing bug - we wrote to the response buffer only if it was nil, after allocating it. This meant, for N consecutive writes to it, only the first would be honored and N-1 would be ignored. This change also eagerly allocates the response buffer with an initial size of 2000, just like KituraNet does it. We don't keep the buffer as an optional anymore. We allocate it in the initializer because we are pretty sure that the HTTPServerResponse initializer always runs on an event loop.
@pushkarnk
Copy link
Contributor Author

Thanks for the review @ianpartridge ! I've added a test

@pushkarnk
Copy link
Contributor Author

Found one more possibility in the code without the changes in this PR. Consider a response that writes twice to the ByteByffer. Because we submit the write task (creating a buffer and writing to it) on the event loop, the first write task may not have been invoked when the second one is about to be submitted. This results in a double allocation of the ByteBuffer, the first buffer being discarded. This pull request fixes that scenario too.

P.S: A glance at the implementation of NIO.SelectableEventLoop.execute() shows that we do impose an order among the submitted tasks, its a FIFO.

@pushkarnk pushkarnk merged commit afcab9d into Kitura:master Sep 5, 2018
@ianpartridge
Copy link
Contributor

Tag a patch release?

@pushkarnk
Copy link
Contributor Author

@ianpartridge tagged v1.0.4

@pushkarnk pushkarnk deleted the buffer-bug branch September 11, 2018 19:05
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.

3 participants