{"action":"created","issue":{"url":"https://api.github.com/repos/ruby/ruby/issues/1232","labels_url":"https://api.github.com/repos/ruby/ruby/issues/1232/labels{/name}","comments_url":"https://api.github.com/repos/ruby/ruby/issues/1232/comments","events_url":"https://api.github.com/repos/ruby/ruby/issues/1232/events","html_url":"https://github.com/ruby/ruby/pull/1232","id":130508969,"number":1232,"title":"net/ftp.rb: add NullSocket#closed? to fix closing not opened connection","user":{"login":"antstorm","id":118353,"avatar_url":"https://avatars.githubusercontent.com/u/118353?v=3","gravatar_id":"","url":"https://api.github.com/users/antstorm","html_url":"https://github.com/antstorm","followers_url":"https://api.github.com/users/antstorm/followers","following_url":"https://api.github.com/users/antstorm/following{/other_user}","gists_url":"https://api.github.com/users/antstorm/gists{/gist_id}","starred_url":"https://api.github.com/users/antstorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antstorm/subscriptions","organizations_url":"https://api.github.com/users/antstorm/orgs","repos_url":"https://api.github.com/users/antstorm/repos","events_url":"https://api.github.com/users/antstorm/events{/privacy}","received_events_url":"https://api.github.com/users/antstorm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-01T22:45:27Z","updated_at":"2016-02-01T22:53:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ruby/ruby/pulls/1232","html_url":"https://github.com/ruby/ruby/pull/1232","diff_url":"https://github.com/ruby/ruby/pull/1232.diff","patch_url":"https://github.com/ruby/ruby/pull/1232.patch"},"body":"Hi there,\r\n\r\nAn instance of `NullSocket` is stored in a `@sock` variable of a new `Net::FTP`, it also has a `#close` method (that obviously does nothing), but it is never called, because a wrapping `Net::FTP#close` checks that `@sock and not @sock.closed?` which crashes with `FTPConnectionError` because there is no method `#closed?` on `NullSocket`. This PR adds it and a test to verify that it works.\r\n\r\nBelow is the way to reproduce the error in the IRB. As you can see it's quite confusing, you'd expect `#closed?` not to raise an error, but return `true` instead.\r\n\r\n```\r\n>> ftp = Net::FTP.new\r\n=> #<Net::FTP:0x007f90c38075e0 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f90c3807590>, @binary=true, @passive=true, @debug_mode=false, @resume=false, @sock=#<Net::FTP::NullSocket:0x007f90c3807568>, @logged_in=false, @open_timeout=nil, @read_timeout=60>\r\n>> ftp.close\r\nNet::FTPConnectionError: not connected\r\n\tfrom /usr/local/var/rbenv/versions/2.3.0/lib/ruby/2.3.0/net/ftp.rb:1277:in `method_missing'\r\n\tfrom /usr/local/var/rbenv/versions/2.3.0/lib/ruby/2.3.0/net/ftp.rb:1168:in `close'\r\n\tfrom (irb):6\r\n\tfrom /usr/local/var/rbenv/versions/2.3.0/bin/irb:11:in `<main>'\r\n>> ftp.closed?\r\nNet::FTPConnectionError: not connected\r\n\tfrom /usr/local/var/rbenv/versions/2.3.0/lib/ruby/2.3.0/net/ftp.rb:1277:in `method_missing'\r\n\tfrom /usr/local/var/rbenv/versions/2.3.0/lib/ruby/2.3.0/net/ftp.rb:1184:in `closed?'\r\n\tfrom (irb):7\r\n\tfrom /usr/local/var/rbenv/versions/2.3.0/bin/irb:11:in `<main>'\r\n```"},"comment":{"url":"https://api.github.com/repos/ruby/ruby/issues/comments/178240528","html_url":"https://github.com/ruby/ruby/pull/1232#issuecomment-178240528","issue_url":"https://api.github.com/repos/ruby/ruby/issues/1232","id":178240528,"user":{"login":"antstorm","id":118353,"avatar_url":"https://avatars.githubusercontent.com/u/118353?v=3","gravatar_id":"","url":"https://api.github.com/users/antstorm","html_url":"https://github.com/antstorm","followers_url":"https://api.github.com/users/antstorm/followers","following_url":"https://api.github.com/users/antstorm/following{/other_user}","gists_url":"https://api.github.com/users/antstorm/gists{/gist_id}","starred_url":"https://api.github.com/users/antstorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antstorm/subscriptions","organizations_url":"https://api.github.com/users/antstorm/orgs","repos_url":"https://api.github.com/users/antstorm/repos","events_url":"https://api.github.com/users/antstorm/events{/privacy}","received_events_url":"https://api.github.com/users/antstorm/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T22:53:17Z","updated_at":"2016-02-01T22:53:17Z","body":"Here's the tracker issue corresponding to this PR — https://bugs.ruby-lang.org/issues/12044"}}