简体   繁体   中英

What is Netty closing channel policy if client does read data and application keeps writing?

My application uses Netty 4.x with TCP sockets to distribute the same data to multiple clients. I want my application to tolerate some clients stalls in data receiving, but if client is too slow I want my application to abandon (close) the connection.

If I understand correctly I can achieve this by configuring proper:

  • sendBufferSize (as far as it allowed by underlying OS)
  • ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK .

Netty Channel.write() writes to ChannelOutboundBuffer . The contents of ChannelOutputBuffers is written to NIO SocketChannel. The operating system sends data by TCP to client.

If client does not read its socket on time, the OS socket sendBuffer fills up, then ChannelOutboundBuffer fills up as far as WRITE_BUFFER_HIGH_WATER_MARK is reached. Next the channel gets unwrtitable state (to avoid out of memory).

What is Netty closing channel policy in this situation? Does Netty close channel if handlers keep writing to it despite it is not writable?

Thanks in advance for any advise.

Netty's policy is to just notify you and will try again once the channel becomes writable again. It's up to the user to decide what is the right action otherwise. Like for example closing the connection or stop reading etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM