SuperSocket.ClientEngine icon indicating copy to clipboard operation
SuperSocket.ClientEngine copied to clipboard

Getting this error when trying to connect in StartReceive()

Open jphoc13 opened this issue 8 years ago • 23 comments

I have a live mobile app using Xamarin.Forms and the iOS version works fine but on Android I can't get past this error. Any advice on how to debug this?

"System.InvalidOperationException: Operation already in progress\n at System.Net.Sockets.SocketAsyncEventArgs.SetLastOperation (System.Net.Sockets.SocketAsyncOperation op) [0x00021] in :0 \n at System.Net.Sockets.Socket.InitSocketAsyncEventArgs (System.Net.Sockets.SocketAsyncEventArgs e, System.AsyncCallback callback, System.Object state, System.Net.Sockets.SocketOperation operation) [0x00039] in :0 \n at System.Net.Sockets.Socket.ReceiveAsync (System.Net.Sockets.SocketAsyncEventArgs e) [0x00073] in :0 \n at SuperSocket.ClientEngine.AsyncTcpSession.StartReceive () [0x0000e] in <4ba236fbf29248a4985a92e6e3907e4a>:0 "

jphoc13 avatar Sep 19 '17 18:09 jphoc13

Which version of ClientEngine do you use right now?

kerryjiang avatar Sep 19 '17 19:09 kerryjiang

Not sure about ClientEngine version but I am using WebSocket4Net dll v4.0.30319. How do I get the ClientEngine version to check it?

jphoc13 avatar Sep 19 '17 19:09 jphoc13

v4.0.30319? It doesn't seem like a product version. It might be the .net framework version.

kerryjiang avatar Sep 19 '17 19:09 kerryjiang

Oh maybe this is it?

0.14.1.0

jphoc13 avatar Sep 19 '17 19:09 jphoc13

Yes, it is.

Could you try the latest version 0.15? Can you use .netstandard library in your project?

kerryjiang avatar Sep 19 '17 19:09 kerryjiang

Can you link the most recent version, not showing up in NUGET? Thanks in advance

jphoc13 avatar Sep 19 '17 19:09 jphoc13

Nevermind found it

jphoc13 avatar Sep 19 '17 19:09 jphoc13

Ok I added the most recent version did a clean and build, restarted visual studios and same error is still occurring.

jphoc13 avatar Sep 19 '17 19:09 jphoc13

My project is using .net4.5, and it was working great for several months.

jphoc13 avatar Sep 19 '17 20:09 jphoc13

I went to Hockey App to get the crash log there as well:

Xamarin caused by: android.runtime.JavaProxyThrowable: System.NotImplementedException: The method or operation is not implemented. System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(Exception exception, int bytesTransferred, SocketFlags flags):0 System.Net.Sockets.MultipleConnectAsync.AsyncFail(Exception e):0 System.Net.Sockets.MultipleConnectAsync.InternalConnectCallback(object sender, SocketAsyncEventArgs args):0 System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e):0 System.Net.Sockets.SocketAsyncEventArgs.Complete():0 at System.Net.Sockets.Socket+<>c.<.cctor>b__306_3 (System.IAsyncResult ares) [0x00057] in :0 System.Net.Sockets.SocketAsyncResult.<>c__DisplayClass27_0.<Complete>b__0(object _):0 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()<3fd174ff54b146228c505f23cf75ce71>:0 System.Threading.ThreadPoolWorkQueue.Dispatch()<3fd174ff54b146228c505f23cf75ce71>:0 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()<3fd174ff54b146228c505f23cf75ce71>:0 dalvik.system.NativeStart.run(Native Method)

jphoc13 avatar Sep 19 '17 21:09 jphoc13

I am still working on this issue. I have narrowed it down further and I believe the issue is with Android and using the DNS host name (which crashes )as opposed to an IPaddress (which works).

jphoc13 avatar Sep 20 '17 17:09 jphoc13

Is there a good approach allow me to reproduce it?

kerryjiang avatar Oct 03 '17 04:10 kerryjiang

What I think may be happening is a timeout on the connection, which occurs after just a few milliseconds on the android end. So I have to find a way to adjust the android timeout.

jphoc13 avatar Oct 03 '17 10:10 jphoc13

I also get the stack trace @jphoc13 reported on Sep. 19 (4 comments up) in my Xamarin app on Android:

  • app uses WebSocket4Net 0.15 with SuperSocket client 0.8.0.13 to connect to Pusher.com
  • works properly so long as device has a network connection
  • exception occurs immediately when device goes into airplane mode

If I downgrade to WebSocket4Net 0.14.1 and remove the SuperSocket library, the app does not crash, and is able to disconnect/reconnect when network comes and goes. The Pusher library I'm using is quite old, so it may need to be updated to work with 0.15.0.

erichedstrom avatar Oct 08 '17 20:10 erichedstrom

As @jphoc13 stated above, it works with IP address and does not work with Host name. I am experiencing the same issue on Xamarin.Android project using SocketIoClientDotNet 1.0.3 with WebSocket4Net 0.15.

valonsejdini avatar Nov 12 '17 15:11 valonsejdini

Could you try adding this environment variable in the application?

Environment.SetEnvironmentVariable("PREFER_DNS_IN_ADVANCE", true);

kerryjiang avatar Dec 02 '17 21:12 kerryjiang

I've got the same issue and used to work fine in 0.14 on Xamarin. I've also found this question on StackOverflow asking the same question. WebSocket4Net simple example fails with “Operation already in progress”

wonea avatar Dec 06 '17 20:12 wonea

Did you try this

Environment.SetEnvironmentVariable("PREFER_DNS_IN_ADVANCE", true);

It is the solution for the error System.NotImplementedException: The method or operation is not implemented

kerryjiang avatar Dec 06 '17 21:12 kerryjiang

I can't seem to code around it with 0.15.1

Environment.SetEnvironmentVariable("PREFER_DNS_IN_ADVANCE", "true", EnvironmentVariableTarget.Machine);
_ws = new WebSocket4Net.WebSocket(uri: Url);
_ws.Open();

_ws.Opened += _ws_Opened;
_ws.Error += _ws_Error;
_ws.Closed += _ws_Closed;
_ws.MessageReceived += _ws_MessageReceived;

I get Operation in progress error immediately after connecting.

Wondering whether this is a bug in .NET

https://github.com/dotnet/corefx/pull/24055 https://github.com/dotnet/corefx/issues/24002

wonea avatar Jan 12 '18 11:01 wonea

This is working for me after updating to 0.15.2 and SuperSocket 0.10. Now I am able to enter/exit airplane mode without the app crashing. I do not have the PREFER_DNS_IN_ADVANCE environment setting.

Thanks @kerryjiang !

erichedstrom avatar Feb 25 '18 00:02 erichedstrom

Really? In Xamarin?

Get Outlook for iOShttps://aka.ms/o0ukef


From: Eric Hedstrom [email protected] Sent: Saturday, February 24, 2018 4:09:22 PM To: kerryjiang/SuperSocket.ClientEngine Cc: Kerry Jiang; Mention Subject: Re: [kerryjiang/SuperSocket.ClientEngine] Getting this error when trying to connect in StartReceive() (#72)

This is working for me after updating to 0.15.2 and SuperSocket 0.10. Now I am able to enter/exit airplane mode without the app crashing. I do not have the PREFER_DNS_IN_ADVANCE environment setting.

Thanks @kerryjianghttps://github.com/kerryjiang !

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/kerryjiang/SuperSocket.ClientEngine/issues/72#issuecomment-368270751, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAb1fHoKVW6LzjiZfR_Sam2ERCMey7FUks5tYKSygaJpZM4Pc2rB.

kerryjiang avatar Feb 25 '18 00:02 kerryjiang

This looks to be the underlying issue in the following: https://github.com/Quobject/SocketIoClientDotNet/issues/133 https://github.com/Quobject/SocketIoClientDotNet/issues/134 https://github.com/Quobject/SocketIoClientDotNet/issues/137

kjeremy avatar Mar 26 '18 19:03 kjeremy

@whybe94 why the thumbs down? These all look to be the same issue.

kjeremy avatar Apr 06 '18 14:04 kjeremy