Problem with that is we will add a lot more complexity on releasing the permit. We got to make sure we don't over release. It needs to be carefully implemented and tested. I will see if I can make it work. 

----- Original Message -----

> From: "Sean Flanigan" <notifications@github.com>
> To: "zanata/zanata-server" <zanata-server@noreply.github.com>
> Cc: "Patrick Huang" <pahuang@redhat.com>
> Sent: Tuesday, March 18, 2014 2:26:27 PM
> Subject: Re: [zanata-server] rhbz988202 - RFE: REST API rate limiting (#390)

> In zanata-war/src/main/java/org/zanata/servlet/RestRateLimiter.java:
> > +                    while (maxActiveSemaphore.availablePermits() !=
> > change.oldLimit) {
> > +                        Uninterruptibles.sleepUninterruptibly(1,
> > +                                TimeUnit.NANOSECONDS);
> > +                    }
> > +                    log.debug("change max active semaphore with new
> > permit");
> > +                    maxActiveSemaphore = new Semaphore(change.newLimit,
> > true);
> > +                    change = null;
> > +                }
> > +            }
> > +        }
> > +        log.debug("before acquire active semaphore:{}",
> > maxActiveSemaphore);
> > +        maxActiveSemaphore.acquireUninterruptibly();
> > +// if we want to enable timeout here,
> > +// we must ensure release is not called when it timed out
> > +//        try {
> > +//            boolean gotIt = maxActiveSemaphore.tryAcquire(30,
> > TimeUnit.SECONDS);

> To avoid wasting threads forever on badly behaved clients, perhaps we should
> have some sort of timeout. I would say 5 minutes would probably be
> reasonable. By then, the client has probably given up anyway, along with any
> web proxy sitting in front of Zanata.

> Plus an error message gives the client developer something to go on, whereas
> having Zanata REST calls hang forever could be very difficult to debug.

> —
> Reply to this email directly or view it on GitHub .