Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
What happens to writes when ChannelOutboundBuffer is full

I'm trying to figure out what happens to write requests when a channel is non-responsive. For example, this happens when the peer suddenly drops off the network, and we never get a RST.

From reading docs and Understanding netty channel buffers and watermarks, it seems that once the high WriterBufferWaterMark is reached, ChannelOutboundBuffer will be considered full, and:

Channel.isWritable() will start to return false.

From Channel.isWritable():

Returns true if and only if the I/O thread will perform the requested write operation immediately. Any write requests made when this method returns false are queued until the I/O thread is ready to process the queued write requests.

My initial question was: What happens when we keep writing anyway?

Where will the data been queued if Netty channel isWritable return false states that there is an internal buffer, and implies it is unbounded.

The question becomes, where exactly are the write requests queued, and more importantly can I observe the size of these queues?

Or: is there some limit when Netty/OS will detect that the connection is broken and needs to be closed?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

It will still be queued in ChannelOutboundBuffer. You are responsible to stop writing once the buffer is full and start again one it empties. You can observe this via ChannelInboundHandler.channelWritabilityChanged(...).

over 4 years ago · Santiago Trujillo Denunciar

0

Looking at the source for ChannelOutboundBuffer in 4.1.37, the method addMessage always adds incoming messages to an internal linked list, regardless of the state of isWritable. This list grows unbounded.

The total byte length of this buffer is reachable via channel.unsafe().outboundBuffer().totalPendingWriteBytes().

For an indirect value, if you don't want to use unsafe(), you can alternatively use channel.bytesBeforeWritable() which will return the queued bytes minus the low watermark.

over 4 years ago · Santiago Trujillo Denunciar

0

What happens when we keep writing anyway?

When you call the ChannelHandlerContext#write method, netty will eventually write the data you want to send into a queue called channelOutboundBuffer.

When the network data receiving speed and processing speed are getting smaller and smaller due to network congestion or the high load of the Netty client, the sliding window of TCP keeps shrinking to reduce the sending of network data until it reaches zero, while the Netty server has a lot of frequent Write operation, continuously write to ChannelOutboundBuffer.

As a result, the data cannot be sent out, but the Netty server is constantly writing data, which will slowly burst the ChannelOutboundBuffer and cause OOM.

So Netty introduced LOW_WATER_MARK and HIGH_WATER_MARK to control the capacity limit of ChannelOutboundBuffer to avoid unlimited growth of ChannelOutboundBuffer

how to observe the size of these queues

you can use ctx.channel().unsafe().outboundBuffer().totalPendingWriteBytes() to Check the total memory usage of the ChannelOutboundBuffer

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda