{"action":"created","issue":{"url":"https://api.github.com/repos/kumaryu/peercaststation/issues/283","repository_url":"https://api.github.com/repos/kumaryu/peercaststation","labels_url":"https://api.github.com/repos/kumaryu/peercaststation/issues/283/labels{/name}","comments_url":"https://api.github.com/repos/kumaryu/peercaststation/issues/283/comments","events_url":"https://api.github.com/repos/kumaryu/peercaststation/issues/283/events","html_url":"https://github.com/kumaryu/peercaststation/issues/283","id":173588224,"number":283,"title":"Monoで自動切断機能が停止する","user":{"login":"plonk","id":1680210,"avatar_url":"https://avatars.githubusercontent.com/u/1680210?v=3","gravatar_id":"","url":"https://api.github.com/users/plonk","html_url":"https://github.com/plonk","followers_url":"https://api.github.com/users/plonk/followers","following_url":"https://api.github.com/users/plonk/following{/other_user}","gists_url":"https://api.github.com/users/plonk/gists{/gist_id}","starred_url":"https://api.github.com/users/plonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plonk/subscriptions","organizations_url":"https://api.github.com/users/plonk/orgs","repos_url":"https://api.github.com/users/plonk/repos","events_url":"https://api.github.com/users/plonk/events{/privacy}","received_events_url":"https://api.github.com/users/plonk/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-27T09:43:50Z","updated_at":"2016-09-07T12:23:53Z","closed_at":"2016-09-07T12:23:53Z","body":"結論から言うとおそらくmonoのバグなのですが、ある程度機序がわかったので書いておきます。\r\n\r\nChannelCleaner などのチャンネルモニターの処理は、AutoResetEvent のタイムアウト・コールバックで定期的に呼び出されますが、mono では不明な理由でコールバックがたまに timeout 引数が false になって呼び出されます。結果、イベントが Set されたようになって、コールバックが解除されます。\r\n\r\n該当部分にデバッグプリントを挿入すると、\r\n\r\n    private AutoResetEvent stoppedEvent = new AutoResetEvent(false);\r\n    private   monitorThreadPool = null;\r\n    private void StartMonitor()\r\n    {\r\n      monitorThreadPool = ThreadPool.RegisterWaitForSingleObject(stoppedEvent, (state,timed_out) => {\r\n        if (!timed_out) {\r\n          (new Logger(typeof(PeerCast))).Info(\"ChannelMonitors OnTimer STOPPED\");\r\n          monitorThreadPool.Unregister(stoppedEvent);\r\n        }\r\n        else {\r\n          (new Logger(typeof(PeerCast))).Info(\"ChannelMonitors OnTimer\");\r\n          foreach (var monitor in ChannelMonitors) {\r\n            monitor.OnTimer();\r\n          }\r\n        }\r\n      }, null, 5000, false);\r\n    }\r\n\r\n次のようなログが取れます。\r\n\r\n    PeerCast: 2016-08-27T10:10:02 [Threadpool worker] INFO  - ChannelMonitors OnTimer\r\n    PeerCast: 2016-08-27T10:10:07 [Threadpool worker] INFO  - ChannelMonitors OnTimer\r\n    PeerCast: 2016-08-27T10:10:12 [Threadpool worker] INFO  - ChannelMonitors OnTimer\r\n    PeerCast: 2016-08-27T10:10:17 [Threadpool worker] INFO  - ChannelMonitors OnTimer\r\n    OutputListener: 2016-08-27T10:10:20 [Threadpool worker] INFO  - Client connected 127.0.0.1:56552\r\n    OutputListener: 2016-08-27T10:10:20 [Threadpool worker] INFO  - Client connected 127.0.0.1:56554\r\n    PeerCast: 2016-08-27T10:10:22 [Threadpool worker] INFO  - ChannelMonitors OnTimer\r\n    OutputListener: 2016-08-27T10:10:24 [Threadpool worker] INFO  - Client connected 127.0.0.1:56558\r\n    PeerCast: 2016-08-27T10:10:27 [Threadpool worker] INFO  - ChannelMonitors OnTimer STOPPED\r\n\r\nまた、添付のプログラム [wait-handle-callback.txt](https://github.com/kumaryu/peercaststation/files/440586/wait-handle-callback.txt) は 1 つの AutoResetEvent に対して 3 つのコールバックを登録するものですが、.Net では `123123...` といつまでも表示されるのに対して、mono では数行表示したところで `...123[1: STOPPED][2: STOPPED]3[3: STOPPED][3: STOPPED]` などとなって停止します。\r\n\r\n動作環境：\r\n\r\n    $ uname -a\r\n    Linux xubuntu-14 4.2.0-41-generic #48-Ubuntu SMP Fri Jun 24 11:28:43 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux\r\n    $ mono --version\r\n    Mono JIT compiler version 4.4.2 (Stable 4.4.2.11/f72fe45 Fri Jul 29 09:58:49 UTC 2016)\r\n    Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com\r\n            TLS:           __thread\r\n            SIGSEGV:       altstack\r\n            Notifications: epoll\r\n            Architecture:  amd64\r\n            Disabled:      none\r\n            Misc:          softdebug \r\n            LLVM:          supported, not enabled.\r\n            GC:            sgen\r\n"},"comment":{"url":"https://api.github.com/repos/kumaryu/peercaststation/issues/comments/245263716","html_url":"https://github.com/kumaryu/peercaststation/issues/283#issuecomment-245263716","issue_url":"https://api.github.com/repos/kumaryu/peercaststation/issues/283","id":245263716,"user":{"login":"plonk","id":1680210,"avatar_url":"https://avatars.githubusercontent.com/u/1680210?v=3","gravatar_id":"","url":"https://api.github.com/users/plonk","html_url":"https://github.com/plonk","followers_url":"https://api.github.com/users/plonk/followers","following_url":"https://api.github.com/users/plonk/following{/other_user}","gists_url":"https://api.github.com/users/plonk/gists{/gist_id}","starred_url":"https://api.github.com/users/plonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plonk/subscriptions","organizations_url":"https://api.github.com/users/plonk/orgs","repos_url":"https://api.github.com/users/plonk/repos","events_url":"https://api.github.com/users/plonk/events{/privacy}","received_events_url":"https://api.github.com/users/plonk/received_events","type":"User","site_admin":false},"created_at":"2016-09-07T12:23:53Z","updated_at":"2016-09-07T12:23:53Z","body":"こちらでもチャンネルが残らなくなりました。直ったようなのでクローズします。"}}
{"actor":{"display_login":"plonk"}}