Tcp twisted data loss problem

I wrote a tcp-based server with the twisted.internet module. This is a high concurrency environment.

I usually send data with an instance of the protocol. Protocol, and I had a problem with this. Some of the tcp connections may be closed due to a timeout, and it seems that I cannot receive any notification, so the data that I wrote in the closed connection may be lost.

And the problem of data loss can be caused in some other way.

Is there a good way to control this? (socket.send can return a state, transport.write seems to have no return)

+4
source share
1 answer

This issue is not specific to Twisted. Your protocol should include confirmation that the data was received if you want to know that it was received.

The result from send() does not tell you that the data was authoritarianly received by the partner; he just says that he was queued up by the kernel for transport. From your point of view, it really doesn’t matter whether the data was queued by Twisted, or your C runtime, or your kernel, or a mid-tier intermediate switch, or a peer kernel, or something else. Maybe it's sent, maybe not. In other words, transport.write() performs additional buffering that does not support send() , ensuring that it always buffers all your bytes, while send() will only buffer some.

You absolutely must have a confirmation message at the application level if you are worried about whether your peers saw your data or not.

+4
source

Source: https://habr.com/ru/post/1369595/


All Articles