Skip to content

Commit

Permalink
Merge pull request #1195 from Aaronontheweb/1194-fix
Browse files Browse the repository at this point in the history
fixed #1194 (ThrottleTransportAdapter overflow bug)
  • Loading branch information
rogeralsing committed Aug 3, 2015
2 parents fb4dbca + 42de92c commit e6ca2ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Binary file modified src/.nuget/NuGet.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion src/core/Akka.Remote.Tests/Transport/ThrottleModeSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using System;
using Akka.Remote.Transport;
using Akka.TestKit;
using Akka.Util;
using Xunit;

namespace Akka.Remote.Tests.Transport
{
public class ThrottleModeSpec : AkkaSpec
{
static readonly long HalfSecond = TimeSpan.FromSeconds(0.5).Ticks;
static readonly long HalfSecond = TimeSpan.FromSeconds(0.5).Ticks.ToNanos();

[Fact]
public void ThrottleMode_must_allow_consumption_of_infinite_amount_of_tokens_when_unthrottled()
Expand Down
4 changes: 3 additions & 1 deletion src/core/Akka.Remote/Transport/ThrottleTransportAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ public override TimeSpan TimeToAvailable(long currentNanoTime, int tokens)

int TokensGenerated(long nanoTimeOfSend)
{
return Convert.ToInt32(((double)(nanoTimeOfSend - _nanoTimeOfLastSend) / TimeSpan.TicksPerMillisecond) * _tokensPerSecond / 1000);
var milliSecondsSinceLastSend = ((nanoTimeOfSend - _nanoTimeOfLastSend).ToTicks()/TimeSpan.TicksPerMillisecond);
var tokensGenerated = milliSecondsSinceLastSend*_tokensPerSecond/1000;
return Convert.ToInt32(tokensGenerated);
}

TokenBucket Copy(int? capacity = null, double? tokensPerSecond = null, long? nanoTimeOfLastSend = null, int? availableTokens = null)
Expand Down

0 comments on commit e6ca2ac

Please sign in to comment.