@@ -563,7 +563,6 @@ private void releaseBackLog(int increment) {
563563 while (leftToAllocate > 0 ) {
564564 leftToAllocate = allocate (this , leftToAllocate );
565565 }
566- allocate (this , increment );
567566 for (Entry <AbstractStream ,int []> entry : backLogStreams .entrySet ()) {
568567 int allocation = entry .getValue ()[1 ];
569568 if (allocation > 0 ) {
@@ -578,6 +577,10 @@ private void releaseBackLog(int increment) {
578577
579578
580579 private int allocate (AbstractStream stream , int allocation ) {
580+ if (log .isDebugEnabled ()) {
581+ log .debug (sm .getString ("upgradeHandler.allocate.debug" , getConnectionId (),
582+ stream .getIdentifier (), Integer .toString (allocation )));
583+ }
581584 // Allocate to the specified stream
582585 int [] value = backLogStreams .get (stream );
583586 if (value [0 ] >= allocation ) {
@@ -593,6 +596,11 @@ private int allocate(AbstractStream stream, int allocation) {
593596 value [0 ] = 0 ;
594597 leftToAllocate -= value [1 ];
595598
599+ if (log .isDebugEnabled ()) {
600+ log .debug (sm .getString ("upgradeHandler.allocate.left" ,
601+ getConnectionId (), stream .getIdentifier (), Integer .toString (leftToAllocate )));
602+ }
603+
596604 // Recipients are children of the current stream that are in the
597605 // backlog.
598606 Set <AbstractStream > recipients = new HashSet <>();
@@ -608,6 +616,11 @@ private int allocate(AbstractStream stream, int allocation) {
608616
609617 int totalWeight = 0 ;
610618 for (AbstractStream recipient : recipients ) {
619+ if (log .isDebugEnabled ()) {
620+ log .debug (sm .getString ("upgradeHandler.allocate.recipient" ,
621+ getConnectionId (), stream .getIdentifier (), recipient .getIdentifier (),
622+ Integer .toString (recipient .getWeight ())));
623+ }
611624 totalWeight += recipient .getWeight ();
612625 }
613626
@@ -616,10 +629,13 @@ private int allocate(AbstractStream stream, int allocation) {
616629 Iterator <AbstractStream > iter = recipients .iterator ();
617630 while (iter .hasNext ()) {
618631 AbstractStream recipient = iter .next ();
619- // +1 is to avoid rounding issues triggering an infinite loop.
620- // Will cause a very slight over allocation but HTTP/2 should
621- // cope with that.
622- int share = 1 + leftToAllocate * recipient .getWeight () / totalWeight ;
632+ int share = leftToAllocate * recipient .getWeight () / totalWeight ;
633+ if (share == 0 ) {
634+ // This is to avoid rounding issues triggering an infinite
635+ // loop. It will cause a very slight over allocation but
636+ // HTTP/2 should cope with that.
637+ share = 1 ;
638+ }
623639 int remainder = allocate (recipient , share );
624640 // Remove recipients that receive their full allocation so that
625641 // they are excluded from the next allocation round.
0 commit comments