Skip to content
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

[UnitTest] GarnetServerTcp.HandleNewConnection throws SocketException while running on macOS #598

Open
plucked opened this issue Aug 17, 2024 · 2 comments

Comments

@plucked
Copy link

plucked commented Aug 17, 2024

Describe the bug

Some unit tests are failing on macOS because of an exception while e.AcceptSocket.NoDelay = true; is called in GarnetServerTcp.HandleNewConnection. It looks like that on macOS, the prior check if (e.SocketError != SocketError.Success) is false when it should be true.

Replacing the code here to:

            try 
            {
                e.AcceptSocket.NoDelay = true;
            } 
            catch (SocketException exception) 
            {
                logger?.LogError(exception, "Error setting NoDelay on accepted socket");
                return false;
            }

Allows me to have all the unit tests that were failing because of this to pass.

Callstack:

Exit code is 134 (Unhandled exception. System.Net.Sockets.SocketException (22): Invalid argument
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName)
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketOptionErrorAndThrowException(SocketError error, String callerName)
   at Garnet.server.GarnetServerTcp.HandleNewConnection(SocketAsyncEventArgs e) in /Users/plucked/Development/garnet/libs/server/Servers/GarnetServerTcp.cs:line 121
   at Garnet.server.GarnetServerTcp.AcceptEventArg_Completed(Object sender, SocketAsyncEventArgs e) in /Users/plucked/Development/garnet/libs/server/Servers/GarnetServerTcp.cs:line 105
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.AcceptCompletionCallback(IntPtr acceptedFileDescriptor, Memory`1 socketAddress, SocketError socketError)
   at System.Net.Sockets.SocketAsyncEngine.System.Threading.IThreadPoolWorkItem.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback())

Steps to reproduce the bug

  1. Clone and run the unit tests

Expected behavior

The unit tests should pass

Screenshots

No response

Release version

main

IDE

Rider 2024.1.5

OS version

macOS 14.5

Additional context

No response

@badrishc
Copy link
Contributor

badrishc commented Aug 17, 2024

Interesting, perhaps e.AcceptSocket.NoDelay = true; can be moved into the try that follows below that section, so that we do not pay for two try/catch sections.

@badrishc
Copy link
Contributor

Interesting, perhaps e.AcceptSocket.NoDelay = true; can be moved into the try that follows below that section, so that we do not pay for two try/catch sections.

If you or anyone can try this and verify that it fixes the problem, feel free to create a PR.

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

No branches or pull requests

2 participants