Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix static analized high priority issues #2391

Merged
merged 1 commit into from
Dec 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ public WriteAll(TimeSpan timeout)
public override bool Equals(object obj)
{
var other = obj as WriteAll;
return obj != null && Timeout == other.Timeout;
return other != null && Timeout == other.Timeout;
}
}
}
4 changes: 2 additions & 2 deletions src/core/Akka.Remote.TestKit/DataTypes.cs
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ public override int GetHashCode()
{
int hashCode = (_node != null ? _node.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_target != null ? _target.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_direction != null ? _direction.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ _direction.GetHashCode();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum can't be null

hashCode = (hashCode * 397) ^ _rateMBit.GetHashCode();
return hashCode;
}
@@ -496,7 +496,7 @@ public override int GetHashCode()
unchecked
{
var hashCode = (_target != null ? _target.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_direction != null ? _direction.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ _direction.GetHashCode();
hashCode = (hashCode * 397) ^ _rateMBit.GetHashCode();
return hashCode;
}
2 changes: 1 addition & 1 deletion src/core/Akka.Remote.TestKit/Player.cs
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ public void Enter(string name)
/// </summary>
public void Enter(TimeSpan timeout, ImmutableList<string> names)
{
_system.Log.Debug("entering barriers {0}", names.Aggregate((a,b) => a = ", " + b));
_system.Log.Debug("entering barriers {0}", names.Aggregate((a, b) => "(" + a + "," + b + ")"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'a' is always rewritten in method, and more clear debug message

var stop = Deadline.Now + timeout;

foreach (var name in names)
1 change: 0 additions & 1 deletion src/core/Akka.Remote/EndpointManager.cs
Original file line number Diff line number Diff line change
@@ -730,7 +730,6 @@ protected void Accepting()
_endpoints.MarkAsQuarantined(gotuid.RemoteAddress, gotuid.Uid,
Deadline.Now + _settings.QuarantineDuration);
_eventPublisher.NotifyListeners(new QuarantinedEvent(gotuid.RemoteAddress, gotuid.Uid));
Context.Stop(pass.Endpoint);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if policy is WasGated Context.Stop(pass.Endpoint) will cause null reference exception
https://github.com/akka/akka/blob/master/akka-remote/src/main/scala/akka/remote/Remoting.scala#L704

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE catch.

else
{
42 changes: 20 additions & 22 deletions src/core/Akka/Actor/ActorCell.FaultHandling.cs
Original file line number Diff line number Diff line change
@@ -59,31 +59,29 @@ private void FaultRecreate(Exception cause)
if (System.Settings.DebugLifecycle)
Publish(new Debug(_self.Path.ToString(), failedActor.GetType(), "Restarting"));

if (failedActor != null)
{
var optionalMessage = CurrentMessage;
var optionalMessage = CurrentMessage;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failedActor is _actor, _actor already checked on null


try
{
// if the actor fails in preRestart, we can do nothing but log it: it’s best-effort
failedActor.AroundPreRestart(cause, optionalMessage);
try
{
// if the actor fails in preRestart, we can do nothing but log it: it’s best-effort

failedActor.AroundPreRestart(cause, optionalMessage);

// run actor pre-incarnation plugin pipeline
var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType());
pipeline.BeforeActorIncarnated(failedActor, this);
}
catch (Exception e)
{
HandleNonFatalOrInterruptedException(() =>
{
var ex = new PreRestartException(_self, e, cause, optionalMessage);
Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message));
});
}
finally
// run actor pre-incarnation plugin pipeline
var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType());
pipeline.BeforeActorIncarnated(failedActor, this);
}
catch (Exception e)
{
HandleNonFatalOrInterruptedException(() =>
{
ClearActor(_actor);
}
var ex = new PreRestartException(_self, e, cause, optionalMessage);
Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message));
});
}
finally
{
ClearActor(_actor);
}

global::System.Diagnostics.Debug.Assert(Mailbox.IsSuspended(), "Mailbox must be suspended during restart, status=" + Mailbox.CurrentStatus());
9 changes: 0 additions & 9 deletions src/core/Akka/Actor/Futures.cs
Original file line number Diff line number Diff line change
@@ -40,18 +40,9 @@ public static Task<T> Ask<T>(this ICanTell self, object message, TimeSpan? timeo
if (provider == null)
throw new ArgumentException("Unable to resolve the target Provider", nameof(self));

ResolveReplyTo();
return Ask(self, message, provider, timeout).CastTask<object, T>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as do nothing

}

internal static IActorRef ResolveReplyTo()
{
if (ActorCell.Current != null)
return ActorCell.Current.Self;

return null;
}

internal static IActorRefProvider ResolveProvider(ICanTell self)
{
if (ActorCell.Current != null)