New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Websockets don't emit last received message if the socket is closed right after that last message. #2508
Comments
Is this behavior different if you use another websocket receiver (other than Neos)? I've checked the code, but I don't see anything Neos side that would block the last message from being received, it looks like Neos just doesn't receive the message in the first place. This could be potentially something in the implementation of the library. We're using this library: https://www.nuget.org/packages/WebSocketSharp Would you be able to test if this behavior happens even if you use this library directly? |
Postman seems to get the message, I'll verify with the library and get back to you! |
I tried using the library directly, and using the native websocket for .net: both show the message payload and then the close signal in sequence. I have not seen the skip message behavior from another client before (tbh I would consider it a bug if I found one that did, as the client would need to have the data somewhere as it's still tcp). Of note, the test url I provided will no longer work, the server has a delay now where it waits 10 seconds before closing the socket due to this issue. Once this gets resolved I'll remove that delay. For repeatibility, here is the main and csproj files for the example. using System;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace WsTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Wrapped test.");
WrappedWs().GetAwaiter().GetResult();
Console.WriteLine("Raw test.");
RawWs().GetAwaiter().GetResult();
}
private static async Task RawWs()
{
using (var ws = new ClientWebSocket())
{
await ws.ConnectAsync(new Uri("ws://localhost:8080/mentee?ticket=856781777414127616"), CancellationToken.None);
while(true)
{
var buf = new byte[1024];
var result = await ws.ReceiveAsync(new ArraySegment<byte>(buf), CancellationToken.None);
switch (result.MessageType)
{
case WebSocketMessageType.Text:
Console.WriteLine($"Direct Got Text {Encoding.UTF8.GetString(buf)}");
break;
case WebSocketMessageType.Binary:
Console.WriteLine($"Direct Got Binary");
break;
case WebSocketMessageType.Close:
Console.WriteLine($"Direct Closed");
return;
}
}
}
}
private static async Task WrappedWs()
{
using (var socket = new WebSocketSharp.WebSocket("ws://localhost:8080/mentee?ticket=856781777414127616"))
{
var tcs = new TaskCompletionSource<int>();
socket.OnOpen += (s, e) => Console.WriteLine($"Wrapped Opened");
socket.OnMessage += (s, e) => Console.WriteLine($"Wrapped Got Message: {e.Data}");
socket.OnError += (s, e) => Console.WriteLine($"Wrapped Error {e.Message}");
socket.OnClose += (s, e) =>
{
Console.WriteLine($"Wrapped Closed {e.Reason}");
tcs.SetResult(0);
};
socket.Connect();
await tcs.Task;
}
}
}
} <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
</ItemGroup>
</Project> And the console output I get from this:
The server is here: https://github.com/Earthmark/mentor-bot but it requires a discord bot ID and channel ID to work, making a mock server may be better. Let me know if you want one of those that matches the output of the bot server to test against. |
Describe the bug
I'm making a bot that people can ask for help through, to keep the load down on the bot if a client connects with a ticket ID that's been completed the server emits the final ticket status, then closes the socket. In postman this looks like this
However, when in Neos that middle message is never received. Instead, the socket opens and closes, but no messages are emitted.
Relevant issues
None found
To Reproduce
1: Have a websocket server that sends a message and then closes. This is a ticket that exabits this behavior, feel free to use this url for testing: wss://mentor-signal.earthmark.net/ws/mentee?ticket=855666359672766506
2: Connect to the server via a neos websocket client
3: See that the client never sees the actual message.
Expected behavior
Regardless of the open and close signals firing, the message received message also fires with the received
message.
Log Files
I don't see anything useful in them, but have at them!
DESKTOP-ERJDBNE - 2021.6.18.4 - 2021-06-18 21_02_46.log
Screenshots / Video
Screenshot was included above, the only visible thing would be no pulses firing in a circuit, but I can add that if requested.
Bug information (please complete the following information):
Additional context
None that I can think of.
Reporters:
Earthmark - Earthmark#0314
The text was updated successfully, but these errors were encountered: