Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Getting this error when trying to connect in StartReceive() #72

Open
jphoc13 opened this issue Sep 19, 2017 · 23 comments
Open

Getting this error when trying to connect in StartReceive() #72

jphoc13 opened this issue Sep 19, 2017 · 23 comments

Comments

@jphoc13
Copy link

jphoc13 commented Sep 19, 2017

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 "

@kerryjiang
Copy link
Owner

Which version of ClientEngine do you use right now?

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

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

@kerryjiang
Copy link
Owner

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

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

Oh maybe this is it?

0.14.1.0

@kerryjiang
Copy link
Owner

Yes, it is.

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

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

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

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

Nevermind found it

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

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

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

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

@jphoc13
Copy link
Author

jphoc13 commented Sep 19, 2017

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.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
Copy link
Author

jphoc13 commented Sep 20, 2017

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).

@kerryjiang
Copy link
Owner

Is there a good approach allow me to reproduce it?

@jphoc13
Copy link
Author

jphoc13 commented Oct 3, 2017

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.

@erichedstrom
Copy link

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.

@valonsejdini
Copy link

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.

@kerryjiang
Copy link
Owner

Could you try adding this environment variable in the application?

Environment.SetEnvironmentVariable("PREFER_DNS_IN_ADVANCE", true);

@wonea
Copy link

wonea commented Dec 6, 2017

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”

@kerryjiang
Copy link
Owner

kerryjiang commented Dec 6, 2017

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

@wonea
Copy link

wonea commented Jan 12, 2018

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

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

@erichedstrom
Copy link

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 !

@kerryjiang
Copy link
Owner

kerryjiang commented Feb 25, 2018 via email

@kjeremy
Copy link

kjeremy commented Mar 26, 2018

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
Copy link

kjeremy commented Apr 6, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants