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 8206273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:36:46+00:00 2026-06-07T08:36:46+00:00

Currently in my pipeline I have a simple handler to reject connections when my

  • 0

Currently in my pipeline I have a simple handler to reject connections when my server gets overloaded:

    public class RequestFilter extends SimpleChannelHandler {

    @Override
    public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception {
            requestLimiter(ctx, e);
            super.channelConnected(ctx, e);
    }
}

private void requestLimiter(final ChannelHandlerContext ctx, final ChannelStateEvent e) {
            if(threshold < counter) {
             ctx.getChannel().close();
            }
    }

When the counter exceeds the threshold, the channel is closed, that all seems to work fine.

Now I’d like to enhance this by first sending an HTTP 503 response prior to closing the channel. What i’ve tried so far is this method below, instead of closing the channel immediatly I try to write a response to the channel and then handle closing it with a channelfuture listener so it’s closed when the write is complete. However whats happening is I get a ton of exceptions about “already sent a response, can’t send more than 1” followed by stack overflow.

protected void sendResponse(Channel channel, HttpResponse response) {
    if (channel.isConnected()) {
        channel.write(response).addListener(ChannelFutureListener.CLOSE);
        log.trace("response sent");
    } else if (!channel.isConnected()) {
        log.trace("attempted to send response, but the channel was closed");
    } else {
        log.trace("Not sure why this would happen");
    }
}

Any thoughts or examples I could look at? thanks

Edit: stacktrace

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.timeout.WriteTimeoutHandler.writeRequested(WriteTimeoutHandler.java:152)
    at org.jboss.netty.handler.stream.ChunkedWriteHandler.flush(ChunkedWriteHandler.java:262)
    at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleDownstream(ChunkedWriteHandler.java:119)
    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)
    at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
    at com.test.RequestFilter.sendResponse(RequestFilter.java:98)
  • 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-06-07T08:36:47+00:00Added an answer on June 7, 2026 at 8:36 am

    I don’t think it is sending multiple responses. I think that it’s [trying] to send one, which is one more than the number of requests which is zero because the the event is being triggered by the connect channel event and the pipeline has yet to see any http requests.

    I would change your code to not do this on connect, but rather, trigger the 503 response on the first request. If the channel is then closed, adios client, but if the client’s first request sneaks in under the threshold, then remove the bouncer from the pipeline (assuming that once a client is in, they’re in for good).

    Make sense ?

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

Sidebar

Related Questions

Currently, I'm working on a project where I have a server - client relationship
I have a pipeline that I currently run on a large university computer cluster.
Currently I have 2 ways of displaying images in a cell, which way will
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
Currently i have a node.js and socket.io application in development on my local machine
I have started developing a new Rails app on my server using RVM, Rails
I have the following simple code in my netty project, it expects to read
I'm currently working on a game/engine that uses OpenGL for rendering, and recently have
I am currently working on creating an import-based pipeline for my indie game using
Currently, my MVC 3 app has a dependency on a static class that is

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.