在Mono中,memcached提供程序在几个小时后因“套接字未连接”500错误而崩溃

时间:2010-11-12 15:10:07

标签: asp.net mono apache2 asp.net-4.0 mod-mono

我正在尝试设置一个单独的asp.net 4.0测试网站,该网站使用memcached提供程序(http://memcachedproviders.codeplex.com/)使用Enyim.Memcached访问memcached。网站和memcachedproviders在Windows服务器上运行良好。

我将工作的asp.net网站移植到mono(Ubuntu 10.10,Mono 2.8),它运行正常并从运行memcached的外部服务器中提取会话,但莫名其妙地,每隔几个小时左右,网站崩溃,以及只返回500错误,说“套接字未连接”这只有在启用了memcachedproviders会话状态时才会发生。

有没有人有经验为单声道会话设置memcachedproveders,或至少知道我应该开始寻找的地方?虽然我熟悉linux和apache,但我对Windows通常比较熟悉,所以可能会有一些我缺少的配置。

据我所知,这是从错误发布时的apache日志,即使从mod_mono启用调试:

[Tue Nov 09 17:53:17 2010] [notice] caught SIGTERM, shutting down
[Tue Nov 09 17:53:19 2010] [notice] Apache/2.2.14 (Ubuntu) mod_mono/2.8 configured -- resuming normal operations
Listening on: /tmp/mod_mono_server_global
Root directory: /
Listening on: /tmp/mod_mono_server_global
Root directory: /
Error: There's already a server listening on /tmp/mod_mono_server_global
mod-mono-server4
mod-mono-server4
Listening on: /tmp/mod_mono_server_mysite
Root directory: /srv/www/mysite
[Tue Nov 09 17:53:58 2010] [error] (104)Connection reset by peer: read_data failed
[Tue Nov 09 17:53:58 2010] [error] Command stream corrupted, last command was -1

web.config中的常规memcached配置类似于:

<enyim.com>
    <memcached>
        <servers>
            <add address="##.##.##.##" port="11211"/>
        </servers>
        <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00"/>
    </memcached>
</enyim.com>
...
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="MemcachedSessionProvider">
    <providers>
        <add name="MemcachedSessionProvider" type="MemcachedProviders.Session.SessionStateProvider,MemcachedProviders" dbType="none" writeExceptionsToEventLog="true"/>
    </providers>
</sessionState>

堆栈跟踪:

System.Net.Sockets.SocketException: The socket is not connected
  at System.Net.Sockets.Socket.Shutdown (SocketShutdown how) [0x00058] in /home/monoweb/mono-2.8/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:698 
  at Enyim.Caching.Memcached.PooledSocket.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
  at Enyim.Caching.Memcached.PooledSocket.Destroy () [0x00000] in <filename unknown>:0 
  at Enyim.Caching.Memcached.MemcachedNode+InternalPoolImpl.ReleaseSocket (Enyim.Caching.Memcached.PooledSocket socket) [0x00000] in <filename unknown>:0 
  at Enyim.Caching.Memcached.PooledSocket.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0 
  at Enyim.Caching.Memcached.PooledSocket.System.IDisposable.Dispose () [0x00000] in <filename unknown>:0 
  at Enyim.Caching.Memcached.ItemOperation.Dispose () [0x00000] in <filename unknown>:0 
  at Enyim.Caching.Memcached.Operation.System.IDisposable.Dispose () [0x00000] in <filename unknown>:0 
  at Enyim.Caching.MemcachedClient.Store (Enyim.Caching.Memcached.ServerPool pool, StoreCommand mode, System.String key, System.Object value, UInt64 casValue, TimeSpan validFor, DateTime expiresAt) [0x00000] in <filename unknown>:0 
  at Enyim.Caching.MemcachedClient.Store (StoreMode mode, System.String key, System.Object value, TimeSpan validFor) [0x00000] in <filename unknown>:0 
  at MemcachedProviders.Session.SessionStateProvider.SetAndReleaseItemExclusive (System.Web.HttpContext context, System.String id, System.Web.SessionState.SessionStateStoreData item, System.Object lockId, Boolean newItem) [0x00000] in <filename unknown>:0 
  at System.Web.SessionState.SessionStateModule.OnReleaseRequestState (System.Object o, System.EventArgs args) [0x0003f] in /home/monoweb/mono-2.8/mcs/class/System.Web/System.Web.SessionState_2.0/SessionStateModule.cs:292 
  at System.Web.HttpApplication+<RunHooks>c__Iterator1.MoveNext () [0x001aa] in /home/monoweb/mono-2.8/mcs/class/System.Web/System.Web/HttpApplication.cs:1026 
  at System.Web.HttpApplication+<Pipeline>c__Iterator2.MoveNext () [0x00ec9] in /home/monoweb/mono-2.8/mcs/class/System.Web/System.Web/HttpApplication.cs:1385 
  at System.Web.HttpApplication.Tick () [0x00000] in /home/monoweb/mono-2.8/mcs/class/System.Web/System.Web/HttpApplication.cs:914 

1 个答案:

答案 0 :(得分:2)

我最后通过首先下载memcachedproviders的源代码并重新编译它来引用enyim.memcached 2.7(最新版本)来解决这个问题。这涉及一些细微的变化。

在此之后,在单声道中我得到了一个不同的错误,在关于string.IndexOfAny(http://msdn.microsoft.com/en-us/library/11w09h50.aspx)的enyim memcached中,其中被检查的字符串为null,因此抛出异常。如果我正在阅读文档,我认为如果参数为null,则仅应该抛出异常,而不是字符串。或者mod_mono随机尝试访问session [null],而asp.net不会。

为了解决这个问题,我下载了enyim memcached源代码,并在函数调用之前添加了一个用空字符串替换null的检查。到目前为止,memcached会议已经持续了24个多小时,而且没有任何障碍。