drachtio / drachtio-server

A SIP call processing server that can be controlled via nodejs applications
https://drachtio.org
MIT License
233 stars 90 forks source link

Broken wire protocol under load #361

Closed tinpotnick closed 3 weeks ago

tinpotnick commented 3 weeks ago

When drachtio receives too many requests at a time, the messages can end up backing up to client.cpp (the wire-protocol connected to Node).

Under the current design the object Client - contains a std::string Buffer (m_msgToSend) to hold the data it has queued for async_write. Async_write will return - with the write queued immediatly. If another request comes in which wishes to send another wire protocol message - this then overwrites the m_msgToSend std::string corrupting the first message if it has not completed its send. Then the Node app throws a major exception and quits.

This fix uses an auto_ptr which wraps a std::string - for the lifetime of the async_write. The Client auto ptr (shared_from_this) and the auto_ptr for the buffer is maintained using a lambda which is cleaned up when the async_write completes and calls back - releasing the buffer at this point.