S2SOutboundPeer - OnConnectionEstablished is not called at all
sneshu
✭
Hello, I struggle a bit where the problem is.
Proxy logs:
and after that immediately in proxy logs are created about subserver disconnection:
There are no error logs in subserver logs.
OnEstablishedConnection is not called at all, nor the OnConnectionFailed in subserver logs.
What am i missing?
Proxy logs:
2020-11-05 07:34:10,260 [12] DEBUG MyApplication.PhotonApplication - Connection request on port 4530 2020-11-05 07:34:10,292 [12] DEBUG MyApplication.PhotonApplication - Created Server PeerProxy has no error logs and subserver 'successfully' connects.
and after that immediately in proxy logs are created about subserver disconnection:
2020-11-05 07:34:10,307 [12] DEBUG MyApplication.PhotonApplication - Server Disconnected ManagedDisconnect -With a code of ManagedDisconnect and a reason of null
There are no error logs in subserver logs.
OnEstablishedConnection is not called at all, nor the OnConnectionFailed in subserver logs.
What am i missing?
0
Comments
-
Just noticed the subserver gets immediately disconnected for no reason0
-
Proxy logs:
2020-11-06 18:16:07,326 [11] DEBUG Photon.SocketServer.PeerBase - Connection state changed from Initializing to Disconnected: peer=T:InboundPhotonPeer,ConnId:2,ip:127.0.0.1:0
Subserver logs:2020-11-06 18:16:07,087 [1] DEBUG Photon.SocketServer.PeerBase - Connection state changed from Disconnected to Connecting: peer=T:OutboundPhotonPeer,ConnId:0,ip:: 2020-11-06 18:16:07,101 [11] DEBUG Photon.SocketServer.ServerToServer.OutboundS2SPeer - OnOutboundConncetionEstablished: remoteEndPoint=127.0.0.1:4530, localEndPoint=127.0.0.1:53188 2020-11-06 18:16:07,305 [11] DEBUG Photon.SocketServer.PeerBase - Connection state changed from Connecting to Disconnected: peer=T:OutboundPhotonPeer,ConnId:2,ip:127.0.0.1:0
Is it problem inside outbound or inbound peer?
I can't localize any issues0 -
I'm in dead end. I don't see anything that would cause exception.
Connection code:public void ConnectToPeer(PeerInfo peerInfo) { var outbound = new OutboundPhotonPeer(Server, peerInfo); if (outbound.ConnectTcp(peerInfo.MasterEndPoint, peerInfo.ApplicationName, PeerInfo.Serialize(peerInfo)) == false) { Log.DebugFormat("Connection refused"); } }
I don't know why, but it happens in proxy logs:2020-11-08 12:22:36,314 [14] DEBUG Photon.SocketServer.PeerBase - Connection state changed from Initializing to Disconnected: peer=T:InboundPhotonPeer,ConnId:2,ip:127.0.0.1:0
It is connecting. As you said, it might be during peer creation, but where exactly should I look for it?
My inbound peer is as simple as that:public class InboundPhotonPeer : InboundS2SPeer { PhotonServerPeer _serverPeer; public PhotonServerPeer ServerPeer { get => _serverPeer; set => _serverPeer = value; } public InboundPhotonPeer(InitRequest initRequest) : base(initRequest) {} protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail) { _serverPeer.OnDisconnect(reasonCode, reasonDetail); } protected override void OnEvent(IEventData eventData, SendParameters sendParameters) { _serverPeer.OnEvent(eventData, sendParameters); } protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { _serverPeer.OnOperationRequest(operationRequest, sendParameters); } protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters) { _serverPeer.OnOperationResponse(operationResponse, sendParameters); } }
0 -
Oh, peer info just holds simple data and has static serializer in it
public class PeerInfo { public IPEndPoint MasterEndPoint { get; set; } public int ConnectionRetryIntervalSeconds { get; set; } public bool IsSiblingConnection { get; set; } public int MaxTries { get; set; } public int NumTries { get; set; } public string ApplicationName { get; set; } public PeerInfo(string ipAddress, int ipPort, int connectRetryIntervalSeconds, bool isSiblingConnection, int maxTries, string applicationName) { MasterEndPoint = new IPEndPoint(IPAddress.Parse(ipAddress), ipPort); ConnectionRetryIntervalSeconds = connectRetryIntervalSeconds; IsSiblingConnection = isSiblingConnection; MaxTries = maxTries; NumTries = 0; ApplicationName = applicationName; } public static byte[] Serialize(object obj) { PeerInfo info = obj as PeerInfo; IEnumerable<byte> returnValue = BitConverter.GetBytes(info.MasterEndPoint.Port) .Concat(BitConverter.GetBytes(info.ConnectionRetryIntervalSeconds)) .Concat(BitConverter.GetBytes(info.IsSiblingConnection)) .Concat(BitConverter.GetBytes(info.MaxTries)) .Concat(BitConverter.GetBytes(info.NumTries)) .Concat(Encoding.ASCII.GetBytes(info.MasterEndPoint.Address.ToString() + "|" + info.ApplicationName)); return returnValue.ToArray(); } public static object Deserialize(byte[] obj) { int port = BitConverter.ToInt32(obj, 0); int retry = BitConverter.ToInt32(obj, 4); bool sibling = BitConverter.ToBoolean(obj, 8); int maxTries = BitConverter.ToInt32(obj, 9); int numTries = BitConverter.ToInt32(obj, 13); byte[] addy = new byte[obj.Length - 17]; Array.Copy(obj, 17, addy, 0, addy.Length); string endString = Encoding.ASCII.GetString(addy); string[] strArray = endString.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); return new PeerInfo(strArray[0], port, retry, sibling, maxTries, strArray[1]) { NumTries = numTries }; } }
I added it to protocol inside class that extends ApplicationBase in Setup()Protocol.TryRegisterCustomType(typeof(PeerInfo), 255, PeerInfo.Serialize, PeerInfo.Deserialize);
0 -
Ok I find out the ApplicationBase calls CreatePeer instead of CreateServerPeer for my new Subserver connection.
protected override PeerBase CreatePeer(InitRequest initRequest)
instead ofprotected override S2SPeerBase CreateServerPeer(InitResponse initResponse, object state)
So the s2s peer was casted to wrong class and thats why it was null.
So what exactly decides to call CreatePeer instead of CreateServerPeer?0