Skip to content

Getting "reactor.netty.channel.AbortedException: Connection has been closed" errors #3714

@dukedom26

Description

@dukedom26

We have a Reactor application.

reactor-netty-core - 1.1.22
spring-boot-starter-webflux - 2.7.18

We are getting intermittent reactor.netty.channel.AbortedException

Error while processing the document for classification reactor.netty.channel.AbortedException: Connection has been closed
	at reactor.netty.http.server.HttpServerOperations.onInboundClose(HttpServerOperations.java:890)
	at reactor.netty.channel.ChannelOperationsHandler.channelInactive(ChannelOperationsHandler.java:73)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:305)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:281)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:274)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:418)
	at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:411)
	at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:376)
	at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:221)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:303)

this is coming while reading the multipart file from the ServerRequest

public static Mono<Map<String, CustomMultipart>> getMultipartFromRequest(ServerRequest request) {
    Flux<DataBuffer> dataBufferFlux = request.body(BodyExtractors.toDataBuffers());
    Mono<byte[]> bytesMono = DataBufferUtils.join(dataBufferFlux)
        .map(dataBuffer -> {
          byte[] bytes = new byte[dataBuffer.readableByteCount()];
          dataBuffer.read(bytes);
          DataBufferUtils.release(dataBuffer);
          return bytes;
        });
    return getMultipartMap(bytesMono);
  }

private static Mono<Map<String, CustomMultipart>> getMultipartMap(Mono<byte[]> bytesMono) {
    return bytesMono.map(requestBytes -> {
      ByteArrayDataSource datasource = new ByteArrayDataSource(requestBytes, "multipart/form-data");
      try {
        MimeMultipart multipart = new MimeMultipart(datasource);
        Map<String, CustomMultipart> multipartHashMap = new HashMap<>();
        for (int i = 0; i < multipart.getCount(); i++) {
          BodyPart bodyPart = multipart.getBodyPart(i);
          ContentDisposition contentDisposition = new ContentDisposition(
              multipart.getBodyPart(i).getHeader("Content-Disposition")[0]);
          CustomMultipart customMultipart = new CustomMultipart();
          if (bodyPart.getContentType().contains("text/plain")) {
            customMultipart.setContent(bodyPart.getContent().toString().getBytes());
          } else {
            SharedByteArrayInputStream byteArrayInputStream = (SharedByteArrayInputStream) multipart.getBodyPart(
                i).getContent();
            int n = byteArrayInputStream.available();
            byte[] bytes = new byte[n];
            int readBytes = byteArrayInputStream.read(bytes, 0, n);
            log.info("Bytes read from multipart file:{}", readBytes);
            customMultipart.setContent(bytes);
          }
          String mimeType = MimeTypeUtils.getMimeType(customMultipart.getContent());
          mimeType = StringUtils.isEmpty(mimeType) ? bodyPart.getContentType() : mimeType;
          customMultipart.setContentType(mimeType);
          customMultipart.setFilename(bodyPart.getFileName());
          multipartHashMap.put(contentDisposition.getParameter("name"), customMultipart);
        }
        return multipartHashMap;
      } catch (Exception e) {
        log.error("Failed to read multipart map from request", e);
        throw new COSException(COSErrors.SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(),
            "Error in reading file", e.getMessage());
      }
    });
  }

Can anyone help me with leads about what can be happening here?

Metadata

Metadata

Assignees

Labels

status/invalidWe don't feel this issue is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions