Skip to content

Client Infinitely Hangs Following Memcached Server Reset #77

@Hobray

Description

@Hobray

When running a dotnet core application with the EnyimMemcached client service registered, if one of the connected servers is stopped and restarted, the IMemcachedClient instance hangs infinitely when calling StoreAsync on the client instance. The last log that comes from from Enyim.Caching.Configuration.MemcachedClientConfiguration is "Socket was reset. (socket GUID)".

Here's the easiest way to reproduce the problem

  • Create a local Memcached Docker container by running the command docker run --name my-memcache -p 127.0.0.1:11211:11211 -d memcached memcached -m 64
  • Create a new dotnet core web application
  • Add the EnyimMemcachedCore NuGet package to the application
  • Register the EnyinMemcached service in the Startup.cs. This is how I'm doing it in mine:
public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddEnyimMemcached((cacheConfig) =>
    {
        //Add servers (point to Docker container on the port forwarded to localhost)
        cacheConfig.AddServer("127.0.0.1", 11211);
    });
    ...
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    ...
    app.UseEnyimMemcached();
    ...
}
  • Now write a controller that takes and IMemcachedClient constructor parameter
  • In the controller add an implementation that makes a call to the IMemcachedClient StoreAsync method
  • Run the application and make sure everything is wired and working properly
  • Now run the docker stop my-memcache command to stop the Memcached Docker container then run docker start my-memcache to get it running again
  • Without ever shutting down the dotnet core application, go back and re-execute the method that calls StoreAsync
  • The logger will write a log indicating that Enyim.Caching.Configuration.MemcachedClientConfiguration is "Aquiring stream from pool..." and then another message will log saying that "Socket (GUID) was reset". After that it will write a log of "Socket was reset. (GUID)".
    At this point the request (and any subsequent session requests) will be hung indefinitely. The only thing that can be done is to restart the application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions