question

Upvotes
Accepted
1 1 3 5

RDP websocket Exception

Hi, I am running a multithreaded C# application which subscribes to pricestream and also getting some reference data. I having this exception caught at run time : System.Net.WebSockets.WebSocketException: 'The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived''

Please can you help solve this ?

Mahmoud.

rdp-apirefinitiv-data-platformrefinitiv-data-platform-libraries
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
16.9k 80 39 63

hI @melarbi,

The default WebSocket implementation within the library uses Microsoft's WebSocketClient which does behave in the following manner:

  • Attempting to invoke any other operations in parallel may corrupt the instance. Attempting to invoke a send operation while another is in progress or a receive operation while another is in progress will result in an exception.


As a result, if you attempt to call AddItems() from different threads, you may run into the issue above. The library does offer the ability to use a different WebSocket implementation - as stated in the above answers. Different libraries may allow for simultaneous access.

Alternatively, you can apply your own thread synchronization to the AddItems() call to ensure it completes before another thread attempts to access.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
16.9k 80 39 63

Hi @melarbi,

Did you write this application from scratch using a public WebSocket API based on example code? Or did you use the community based RDP Library for .Net?

It would be helpful to understand where you started from as applications written against RDP require token refresh on both the gateway as well as the connection into the real-time streaming services.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 1 3 5

Hi @nick.zincone.1. I am using the example code from RDP Library .NET examples and I am changing it to my needs. The list of names for which I create a "subscription" is dynamic and changes through the day. Initial subscription list is created at start up then new RICs are added to the stream ( stream.AddItems ( "RIC-NEW") ) using a blocking call.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
16.9k 80 39 63

Thanks @melarbi,

As you can imagine, I can't do much without a code sample that demonstrates the issue. Does the error occur systematically? That is, can you reproduce it every time? Is it random? Where/what are you specifically doing that is causing the issue? You mentioned it is multi-threaded - what are the different threads doing? Are they both calling into the API?

thanks.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
16.9k 80 39 63

Hi @melarbi,

The RDP Library for .Net uses 3rd party WebSocket libraries. In addition, the library has the ability to implement its own WebSocket implementation.

Within the example package, 3.0.03-Core-WebSocket provides the way for users to choose different WebSocket implementations. In addition, that example also implements code for another 3rd WebSocket library and how to register it with the library.

It is quite possible the WebSocket library you are using may have issues. If you can systematically recreate the issue, I would suggest registering a different implementation to see if this helps.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
7.6k 15 6 9

@melarbi

It sounds like currently, you have added more complex codes on top of the example. It is quite hard to tell for possible issues because we do not have sample codes and don't know your apps' actual implementation.


From the latest version of RDPLibrary for .NET, you can choose the different WebSocket library(ClientWebsocket, WebsocketSharp, Websocket4net).

Not sure which one is the Websocket Library your application is using?


If the problem always occurs when you run the app. Can you change Logger to Trace level by setting

Log.Level = NLog.LogLevel.Trace; 

at the begging of the app.

It usually creates RDPLog_<pid>.log under the running directory. Perhaps the log may contain some error that helps pinpoint the possible root cause.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.