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

发布于 2024-10-02 01:57:52 字数 4327 浏览 1 评论 0原文

我正在尝试建立一个单声道 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 会话状态时才会发生这种情况。

有谁有为单声道会话设置memcachedproviders的经验,或者至少知道我应该从哪里开始寻找?虽然我熟悉 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 

I am trying to set up a mono asp.net 4.0 test website that uses memcached providers (http://memcachedproviders.codeplex.com/) using Enyim.Memcached to access memcached. The website and memcachedproviders work fine on a windows server.

I ported over the working asp.net website to mono (Ubuntu 10.10, Mono 2.8), and it runs correctly and pulls sessions from an external server running memcached, but inexplicably, every couple hours or so, the website crashes, and just returns a 500 error saying "The socket is not connected" This only happens when memcachedproviders session state is enabled.

Does anyone have any experience setting up memcachedproveders for a session in mono, or know at least where I should begin looking? While I'm familiar with linux and apache, I'm generally more comfortable with windows so there may be some configuration I'm missing.

As far as i can tell, this is the log from apache from the time the error, even with debugging enabled from 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

The general memcached configuration in web.config is something like:

<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>

And the stack trace:

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相守太难 2024-10-09 01:57:52

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

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

为了解决这个问题,我下载了 enyim memcached 源代码,并添加了一个检查,在函数调用之前将 null 替换为空字符串。到目前为止,memcached 会话已连续运行超过 24 小时,没有出现任何故障。

I ended up fixing this by first downloading the source for memcachedproviders, and recompiling it to reference enyim.memcached 2.7 (the latest version). This involved some minor changes.

After this, in mono I instead got a different error, within enyim memcached regarding string.IndexOfAny ( http://msdn.microsoft.com/en-us/library/11w09h50.aspx ) where the string being checked was null, and so was throwing an exception. If I'm reading the docs right, I think that it's only supposed to throw an exception if the parameter is null, not if the string is. Either that or mod_mono randomly tries to access session[null], whereas asp.net does not.

To fix this, I downloaded the enyim memcached source, and added a check that would replace a null with an empty string before the function call. memcached sessions have been up for over 24 hours so far without a hitch now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文