diff --git a/src/Orleans.Runtime/Messaging/Gateway.cs b/src/Orleans.Runtime/Messaging/Gateway.cs index dec6808011..a97fc482f3 100644 --- a/src/Orleans.Runtime/Messaging/Gateway.cs +++ b/src/Orleans.Runtime/Messaging/Gateway.cs @@ -436,16 +436,19 @@ private void Drain(ClientState clientState) private bool Send(Message msg, ClientState client) { + var connection = client.Connection; + if (connection is null) return false; + try { - client.Connection.Send(msg); + connection.Send(msg); gatewaySends.Increment(); return true; } catch (Exception exception) { - gateway.RecordClosedConnection(client.Connection); - client.Connection.Abort(new ConnectionAbortedException("Exception posting a message to sender. See InnerException for details.", exception)); + gateway.RecordClosedConnection(connection); + connection.Abort(new ConnectionAbortedException("Exception posting a message to sender. See InnerException for details.", exception)); return false; } }