Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

permessage_deflate seems not thread safe #615

Open
KyleNyenhuis opened this issue Jan 25, 2017 · 2 comments
Open

permessage_deflate seems not thread safe #615

KyleNyenhuis opened this issue Jan 25, 2017 · 2 comments

Comments

@KyleNyenhuis
Copy link

For a given server (asio transport) with permessage_deflate turned on it eventually (quickly) sends corrupted messages. I believe this is due to the fact that I'm "send()"ing messages on threads other than my server's io_service thread.

At first glance in extensions/permessage_deflate/enabled.hpp I see the buffer is used for both compress and decompress:
size_t m_compress_buffer_size;
lib::unique_ptr_uchar_array m_compress_buffer;

But when I attach a debugger I'm not finding any locks in my backtrace that would prevent a compress() and decompress() from occurring at the same time. (on different threads)

Moving all send() calls to the main io_service thread corrects the issue for me.
I thought I read that it should be okay to send() outside of the io_service thread. Am I missing somthing?

@pdgendt
Copy link

pdgendt commented Apr 3, 2017

I think we have this issue as well. The websockets are closed at random times, with code 1006 or 1007 and reason, Could not decode a text frame as UTF-8 or Invalid frame header.

If we disable the deflate setting, then the connection is kept open but if we enable it we see a close event after 5~60 minutes.

Our application is multi-threaded where all relevant threads execute io_service.run().

zaphoyd pushed a commit that referenced this issue Jun 11, 2017
…ruption when reading and writing from separate threads. references #633 references #615
@zaphoyd
Copy link
Owner

zaphoyd commented Jun 11, 2017

It definitely should be safe to call send on separate threads than the main I/O thread. The situation with the compress buffer definitely violates this. I've applied an update very similar to one @pdgendt posted in #633 to the develop branch that should fix this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants