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

PlatformNotSupportedException trying to sniff platform in ConnectionMultiplexer.Connect() #582

Closed
daniel-meismer-zocdoc opened this issue Feb 27, 2017 · 3 comments

Comments

@daniel-meismer-zocdoc
Copy link
Contributor

daniel-meismer-zocdoc commented Feb 27, 2017

I got an error connecting to redis in an AWS Lambda function on coreclr (stack trace below).
The error is triggered by the internal code that tries to optimize the socket for localhost connections on Windows, specifically the code in SocketManager.cs that tries to determine if it is running on Windows.

To verify, I copied the redis client code into my project, commented out the call to SetFastLoopbackOption (on line 178), and did not get the error when I deployed.

To fix, I'd propose adding a catch(PlatformNotSupportedException) { /* ignore */ } to the OS sniffing code to the try/catch at lines 269-280 since we don't really care if it fails.

Stack trace

One or more errors occurred. (One or more errors occurred. (Operation is not supported on this platform.)): AggregateException
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at lambda_method(Closure , Stream , Stream , ContextInfo )
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func`1 multiplexerFactory, TextWriter log)
   at Zd.RefDataConsumer.Lambda.EntryPoint.LongLivedConnections.GetRedisConnectionMultiplexer() in /app/src/Zd.RefDataConsumer.Lambda/EntryPoint.cs:line 119
   at Zd.RefDataConsumer.Lambda.EntryPoint.GetProcessorImpl(ILambdaContext context) in /app/src/Zd.RefDataConsumer.Lambda/EntryPoint.cs:line 52
   at Zd.RefDataConsumer.Lambda.EntryPoint.<HandleKinesisRecord>d__0.MoveNext()
Operation is not supported on this platform.: PlatformNotSupportedException
   at System.Runtime.InteropServices.OSPlatform.get_Windows()
   at StackExchange.Redis.SocketManager.SetFastLoopbackOption(Socket socket)
   at StackExchange.Redis.SocketManager.BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
   at StackExchange.Redis.PhysicalConnection.BeginConnect(TextWriter log)
   at StackExchange.Redis.PhysicalBridge.GetConnection(TextWriter log)
   at StackExchange.Redis.ServerEndPoint..ctor(ConnectionMultiplexer multiplexer, EndPoint endpoint, TextWriter log)
   at StackExchange.Redis.ConnectionMultiplexer.<ReconfigureAsync>d__123.MoveNext()

Investigation Details

I had trouble believing a call to get the OSPlatform.Windows property would ever fail, so I deployed this code in a lambda function to verify:

[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
public string HandleDerp(string ignoreInput)
{
    try
    {
        var platform = OSPlatform.Windows;
        return "no problem";
    }
    catch (Exception ex)
    {
        return $"facepalm{Environment.NewLine}{ex}";
    }
}

When I tested in the aws console I got

facepalm
System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Runtime.InteropServices.OSPlatform.get_Windows()
   at Zd.Availability.ProfessionalRefData.Lambda.EntryPoint.HandleDerp(String ignoreInput)

So I stand corrected.
For anyone interested in writing an AWS lambda function, here's their framework and documentation


I am successfully using the redis client in an AWS ECS task (running in the microsoft dotnet core docker image). It uses the same connection logic as my lambda, and there are no issues.
The differences between the two environments are:

  • AWS Lambda is dotnet core 1.0, while my docker image is 1.1
  • AWS Lambda runs on Amazon linux while my docker image is debian

Originally I thought this error was related to dotnet core 1.0.x but I ran my test code on the older docker images for 1.0.x and they all worked, suggesting the problem is somehow with Amazon Linux.

@NickCraver
Copy link
Collaborator

We've heard several issues with Amazon in general here (many of which have passed), are you still experiencing any issues with this?

@daniel-meismer-zocdoc
Copy link
Contributor Author

@NickCraver I think this issue can be closed, the problem in the description is fixed. Thanks!

@NickCraver
Copy link
Collaborator

Thanks! Closing out :)

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