Return write buffer to pool on write error#427
Conversation
|
Would it make more sense to put this cleanup code in a defer? |
|
@kisielk After looking into your suggestion, I realized that I missed another error case. The code belongs in messageWriter.fatal. That method should be renamed to finishWrite for symmetry with the existing prepWrite method. I'll push a change later today. |
|
Another thing is, should |
Fix bug where connection did not return the write buffer to the pool after a write error. Add test for the same. Rename messsageWriter.fatal method to endMessage and consolidate all message cleanup code there. This ensures that the buffer is returned to pool on all code paths. Rename Conn.prepMessage to beginMessage for symmetry with endMessage. Move some duplicated code at calls to prepMessage to beginMessage. Bonus improvement: Adjust message and buffer size in TestWriteBufferPool to test that pool works with fragmented messages.
|
Please look again. The messageWriter.fatal method contained the code to cleanup after a message. I moved the buffer cleanup to that method and renamed the method to endMessage to make the intent of the method clearer. I also renamed Conn.prepMessage to beginMessage for symmetry with endMessage. I also moved some duplicated code at the beginMessage call sites to beginMessage. |
|
Can somebody please take a look? |
Fix bug where connection did not return the write buffer to the pool
after a write error. Add test for the same.
Bonus improvement: Adjust message and buffer size in TestWriteBufferPool
to test that pool works with fragmented messages.