Skip sending rather than immediately close while publishing

This commit is contained in:
Alex Hultman
2020-05-20 17:10:20 +02:00
committed by GitHub
parent a58ea98d18
commit 20b1676590
+10 -6
View File
@@ -60,18 +60,22 @@ struct WebSocketContextData {
/* We rely on writing to regular asyncSockets */ /* We rely on writing to regular asyncSockets */
auto *asyncSocket = (AsyncSocket<SSL> *) s->user; auto *asyncSocket = (AsyncSocket<SSL> *) s->user;
/* Check if we now have too much backpressure (todo: don't buffer up before check) */
if (!maxBackpressure || (unsigned int) asyncSocket->getBufferedAmount() < maxBackpressure) {
/* Note: this assumes we are not corked, as corking will swallow things and fail later on */
auto [written, failed] = asyncSocket->write(data.data(), (int) data.length()); auto [written, failed] = asyncSocket->write(data.data(), (int) data.length());
if (!failed) { if (!failed) {
asyncSocket->timeout(this->idleTimeout); asyncSocket->timeout(this->idleTimeout);
} else { }
/* Note: this assumes we are not corked, as corking will swallow things and fail later on */
/* Check if we now have too much backpressure (todo: don't buffer up before check) */ /* Failing here must not immediately close the socket, as that could result in stack overflow,
if ((unsigned int) asyncSocket->getBufferedAmount() > maxBackpressure) { * iterator invalidation and other TopicTree::drain bugs. We may shutdown the reading side of the socket,
asyncSocket->close(); * causing next iteration to error-close the socket from that context instead, if we want to */
}
} }
/* If we have too much backpressure, simply skip sending from here */
/* Reserved, unused */ /* Reserved, unused */
return 0; return 0;
}) { }) {