{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/2337","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2337/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2337/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2337/events","html_url":"https://github.com/crystal-lang/crystal/pull/2337","id":142184082,"number":2337,"title":"failing test: udp socket send","user":{"login":"miketheman","id":529516,"avatar_url":"https://avatars.githubusercontent.com/u/529516?v=3","gravatar_id":"","url":"https://api.github.com/users/miketheman","html_url":"https://github.com/miketheman","followers_url":"https://api.github.com/users/miketheman/followers","following_url":"https://api.github.com/users/miketheman/following{/other_user}","gists_url":"https://api.github.com/users/miketheman/gists{/gist_id}","starred_url":"https://api.github.com/users/miketheman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miketheman/subscriptions","organizations_url":"https://api.github.com/users/miketheman/orgs","repos_url":"https://api.github.com/users/miketheman/repos","events_url":"https://api.github.com/users/miketheman/events{/privacy}","received_events_url":"https://api.github.com/users/miketheman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-03-20T17:30:39Z","updated_at":"2016-04-01T23:20:12Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/2337","html_url":"https://github.com/crystal-lang/crystal/pull/2337","diff_url":"https://github.com/crystal-lang/crystal/pull/2337.diff","patch_url":"https://github.com/crystal-lang/crystal/pull/2337.patch"},"body":"This commit should expose some of the flakiness when trying to open a\r\nsocket once, and send multiple messages to a non-listening server.\r\n\r\nTypically, the first test will pass, and the second one fails. There definitely seems to be an 'ordering' thing going on here, as in testing I was able to emit 1, 2 messages successfully most of the time with no stacktrace:\r\n\r\n```\r\n       Error writing file: Connection refused\r\n       [4548360178] *CallStack::unwind:Array(Pointer(Void)) +82\r\n       [4548360081] *CallStack#initialize<CallStack>:Array(Pointer(Void)) +17\r\n       [4548360040] *CallStack::new:CallStack +40\r\n       [4548370505] *Exception@Exception#initialize<Errno, String>:CallStack +41\r\n       [4548370435] *Errno#initialize<Errno, String>:CallStack +115\r\n       [4548370289] *Errno::new<String>:Errno +113\r\n       [4548640355] *UDPSocket@IO::FileDescriptor#unbuffered_write<UDPSocket, Slice(UInt8)>:Int32 +627\r\n       [4548644656] *UDPSocket@IO::Buffered#write<UDPSocket, Slice(UInt8)>:Int32? +112\r\n       [4548644361] *UDPSocket@IO#write_utf8<UDPSocket, Slice(UInt8)>:Nil +105\r\n       [4548359706] *String#to_s<String, UDPSocket>:Nil +74\r\n       [4548644232] *UDPSocket@IO#<<<UDPSocket, String>:UDPSocket +24\r\n       [4548326279] ~proc( -> Void)@./spec/std/socket_spec.cr:236 +87\r\n       [4548298164] *it<String, String, Int32, &( -> Void)>:(Array(Spec::Result) | Bool | Nil) +420\r\n       [4548325038] ~proc( -> Void)@./spec/std/socket_spec.cr:227 +142\r\n       [4548505370] *Spec::RootContext::describe<String, String, Int32, &( -> Void)>:Spec::Context+ +314\r\n       [4548324883] *describe<UDPSocket:Class, String, Int32, &( -> Void)>:Spec::Context+ +51\r\n       [4548284608] __crystal_main +39120\r\n       [4548294120] main +40\r\n```\r\n\r\nThis is in attempt to make a singleton client for the statsd.cr shard, that should have a graceful degradation model for the listener failing.\r\n\r\nCurrently, [creating and closing a UDPSocket per request works](https://github.com/miketheman/statsd.cr/blob/b4cc5821ee2dc16e64bfdab022d78ed5d145b6c3/src/statsd/client.cr#L36-L41), but is far from optimal."},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/204604715","html_url":"https://github.com/crystal-lang/crystal/pull/2337#issuecomment-204604715","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2337","id":204604715,"user":{"login":"miketheman","id":529516,"avatar_url":"https://avatars.githubusercontent.com/u/529516?v=3","gravatar_id":"","url":"https://api.github.com/users/miketheman","html_url":"https://github.com/miketheman","followers_url":"https://api.github.com/users/miketheman/followers","following_url":"https://api.github.com/users/miketheman/following{/other_user}","gists_url":"https://api.github.com/users/miketheman/gists{/gist_id}","starred_url":"https://api.github.com/users/miketheman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miketheman/subscriptions","organizations_url":"https://api.github.com/users/miketheman/orgs","repos_url":"https://api.github.com/users/miketheman/repos","events_url":"https://api.github.com/users/miketheman/events{/privacy}","received_events_url":"https://api.github.com/users/miketheman/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T23:20:12Z","updated_at":"2016-04-01T23:20:12Z","body":"@asterite Thanks for the investigation. Does that mean that I should be doing something like this?\r\n```crystal\r\ndef send_with_except(client, message, destination)\r\n  begin\r\n    client.send(message, destination)\r\n  rescue Errno\r\n  end\r\nend\r\n```\r\n\r\nIs there a better exception I should be handling? I will probably add a debug log at some point, and that would go in the `rescue` section."}}