Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:21:52+00:00 2026-05-31T21:21:52+00:00

I am working on a Netty server, I am having issues with a custom

  • 0

I am working on a Netty server, I am having issues with a custom handler I created to receive file uploads via HTTP PUT requests. Everything seems to work fine when I just send a few files at a time, however after about 300 connections the server seems to “break”. The server will then throw the follow exception on each received request. After this starts happening, the server no longer handles the requests and needs to be restarted:

    java.lang.IllegalStateException: cannot send more responses than requests
        at org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
        at org.jboss.netty.handler.execution.ExecutionHandler.handleDownstream(ExecutionHandler.java:165)
        at org.jboss.netty.channel.Channels.write(Channels.java:605)
        at org.jboss.netty.channel.Channels.write(Channels.java:572)
....

Here is my handler source channelRecieved, all the requests i’m handling are chunked, so I will include those methods below:

@Override
public void messageReceived(ChannelHandlerContext context, MessageEvent event) throws Exception {
    try {
        log.trace("Message recieved");
        if (newMessage) {
            log.trace("New message");
            HttpRequest request = (HttpRequest) event.getMessage();
            setDestinationFile(context, request);
            newMessage = false;
            if (request.isChunked()) {
                log.trace("Chunked request, set readingChunks true and create byte buffer");
                requestContentStream = new ByteArrayOutputStream();
                readingChunks = true;
                return;
            } else {
                log.trace("Request not chunked");
                writeNonChunkedFile(request);
                requestComplete(event);
                return;
            }
        } else if (readingChunks){
            log.trace("Reading chunks");
            HttpChunk chunk = (HttpChunk) event.getMessage();
            if (chunk.isLast()) {
                log.trace("Read last chunk");
                readingChunks = false;
                writeChunkedFile();
                requestComplete(event);
                return;
            } else {
                log.trace("Buffering chunk content to byte buffer");
                requestContentStream.write(chunk.getContent().array());
                return;
            }
            // should not happen
        } else {
            log.error("Error handling of MessageEvent, expecting a new message or a chunk from a previous message");
        }
    } catch (Exception ex) {
        log.error("Exception: [" + ex + "]");
        sendError(context, INTERNAL_SERVER_ERROR);
    }
}

This is how I am writing the chunked requests:

private void writeChunkedFile() throws IOException {
    log.trace("Writing chunked file");
    byte[] data = requestContentStream.toByteArray();
    FileOutputStream fos = new FileOutputStream(destinationFile);
    fos.write(data);
    fos.close();
    log.debug("File upload complete, [chunked], path: [" + destinationFile.getAbsolutePath() + "] size: [" + destinationFile.length() + "] bytes");
}

This is how I send the response and close the connection:

private void requestComplete(MessageEvent event) {
    log.trace("Request complete");
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    Channel channel = event.getChannel();
    ChannelFuture cf = channel.write(response);
    cf.addListener(ChannelFutureListener.CLOSE);
}

I have tried a few things in requestComplete, one being just channel.close() which didn’t seem to help. Any other thoughts or ideas?

Here is my pipeline:

@Override
public ChannelPipeline getPipeline() throws Exception {
    final ChannelPipeline pipeline = pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("deflater", new HttpContentCompressor());
    pipeline.addLast("ExecutionHandler", executionHandler);

pipeline.addLast(“handler”, new FileUploadHandler());
return pipeline;
}

Thanks for any thoughts or ideas

Edit: sample log entry when logging between deflator and handler in pipeline:

2012-03-23T07:46:40.993 [New I/O server worker #1-6] WARN  NbEvents [c.c.c.r.d.l.s.h.SbApiMessageLogger.writeRequested] [] - Sending [DefaultHttpResponse(chunked: false)
HTTP/1.1 100 Continue]
2012-03-23T07:46:40.995 [New I/O server worker #1-6] WARN  NbEvents [c.c.c.r.d.l.s.h.SbApiMessageLogger.writeRequested] [] - Sending [DefaultHttpResponse(chunked: false)
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=UTF-8]
2012-03-23T07:46:41.000 [New I/O server worker #1-7] DEBUG NbEvents [c.c.c.r.d.l.s.h.SbApiMessageLogger.messageReceived] [] - Received [PUT /a/deeper/path/testFile.txt HTTP/1.1
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.12.9.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
Host: 192.168.0.1:8080
Accept: */*
Content-Length: 256000
Expect: 100-continue
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:21:53+00:00Added an answer on May 31, 2026 at 9:21 pm

    This ended up being a problem with my implementation, not related to any of the code posted here, the logic posted here seems sound and works fine. That said, many thanks to all for the helpful comments!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on writing a custom property Handler for our custom file type in windows
I wrote a small netty server program. It is working with all phones, but
I am working on creating a Snappy Encoder and Decoder for Netty. I am
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a website http://www.ArenaText.com written in asp.net with Microsoft AJAX control toolkit. iPad
I'm trying to implement long polling using Netty and jQuery. I have it working
Working example: http://alpha.jsfiddle.net/gTpWv/ Both of the methods work separately, but once regexp for smilies
Working live URL showing problem: http://69.24.73.172/demos/newDemo/test.html The HTML : <div class="small-vote"> <a href="#" class="s
Working through this for fun: http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/ Example calculation of nullable and first uses a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.