diff --git a/amqp/transport.py b/amqp/transport.py
index 177fb22..b87f9fe 100644
--- a/amqp/transport.py
+++ b/amqp/transport.py
@@ -272,7 +272,11 @@ class _AbstractTransport:
 
     def close(self):
         if self.sock is not None:
-            self._shutdown_transport()
+            try:
+                self._shutdown_transport()
+            except OSError:
+                pass
+
             # Call shutdown first to make sure that pending messages
             # reach the AMQP broker if the program exits after
             # calling this method.
@@ -280,7 +284,11 @@ class _AbstractTransport:
                 self.sock.shutdown(socket.SHUT_RDWR)
             except OSError:
                 pass
-            self.sock.close()
+
+            try:
+                self.sock.close()
+            except OSError:
+                pass
             self.sock = None
         self.connected = False
 

diff --git a/t/unit/test_transport.py b/t/unit/test_transport.py
index b111497..348b6c2 100644
--- a/t/unit/test_transport.py
+++ b/t/unit/test_transport.py
@@ -587,6 +587,16 @@ class test_AbstractTransport_connect:
         self.t.connect()
         assert self.t.connected and self.t.sock is sock_obj
 
+    def test_close__close_error(self):
+        # sock.close() can raise an error if the fd is invalid
+        # make sure the socket is properly deallocated
+        sock = self.t.sock = Mock()
+        sock.unwrap.return_value = sock
+        sock.close.side_effect = OSError
+        self.t.close()
+        sock.close.assert_called_with()
+        assert self.t.sock is None and self.t.connected is False
+
 
 class test_SSLTransport:
     class Transport(transport.SSLTransport):
@@ -835,6 +845,14 @@ class test_SSLTransport:
         self.t._shutdown_transport()
         assert self.t.sock is sock.unwrap()
 
+    def test_close__unwrap_error(self):
+        # sock.unwrap() can raise an error if the was a connection failure
+        # make sure the socket is properly closed and deallocated
+        sock = self.t.sock = Mock()
+        sock.unwrap.side_effect = OSError
+        self.t.close()
+        assert self.t.sock is None
+
     def test_read_EOF(self):
         self.t.sock = Mock(name='SSLSocket')
         self.t.connected = True

5.0.7 SSL connection problem
After upgrade to the 5.0.7 celery workers are unable to connect to RabbitMQ (3.9.11) using SSL. Worker dies immediately after start and following exceptions are logged. Reverting to 5.0.6 solves the connection problem.

<pre>2021-12-15 07:31:14 [11] CRITICAL Unrecoverable error: OperationalError('[Errno 32] Broken pipe') (/usr/local/lib/python3.9/site-packages/celery/worker/worker.py:start)
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/kombu/connection.py", line 524, in _ensured
    return fun(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/kombu/messaging.py", line 193, in _publish
    [maybe_declare(entity) for entity in declare]
  File "/usr/local/lib/python3.9/site-packages/kombu/messaging.py", line 193, in <listcomp>
    [maybe_declare(entity) for entity in declare]
  File "/usr/local/lib/python3.9/site-packages/kombu/messaging.py", line 99, in maybe_declare
    return maybe_declare(entity, self.channel, retry, **retry_policy)
  File "/usr/local/lib/python3.9/site-packages/kombu/common.py", line 110, in maybe_declare
    return _maybe_declare(entity, channel)
  File "/usr/local/lib/python3.9/site-packages/kombu/common.py", line 150, in _maybe_declare
    entity.declare(channel=channel)
  File "/usr/local/lib/python3.9/site-packages/kombu/entity.py", line 180, in declare
    return (channel or self.channel).exchange_declare(
  File "/usr/local/lib/python3.9/site-packages/amqp/channel.py", line 608, in exchange_declare
    self.send_method(
  File "/usr/local/lib/python3.9/site-packages/amqp/abstract_channel.py", line 57, in send_method
    conn.frame_writer(1, self.channel_id, sig, args, content)
  File "/usr/local/lib/python3.9/site-packages/amqp/method_framing.py", line 183, in write_frame
    write(view[:offset])
  File "/usr/local/lib/python3.9/site-packages/amqp/transport.py", line 355, in write
    self._write(s)
  File "/usr/local/lib/python3.9/site-packages/amqp/transport.py", line 599, in _write
    n = write(s)
  File "/usr/local/lib/python3.9/ssl.py", line 1118, in write
    return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/kombu/connection.py", line 447, in _reraise_as_library_errors
    yield
  File "/usr/local/lib/python3.9/site-packages/kombu/connection.py", line 536, in _ensured
    self.collect()
  File "/usr/local/lib/python3.9/site-packages/kombu/connection.py", line 366, in collect
    gc_transport(self._connection)
  File "/usr/local/lib/python3.9/site-packages/kombu/transport/pyamqp.py", line 173, in _collect
    connection.collect()
  File "/usr/local/lib/python3.9/site-packages/amqp/connection.py", line 470, in collect
    self._transport.close()
  File "/usr/local/lib/python3.9/site-packages/amqp/transport.py", line 275, in close
    self._shutdown_transport()
  File "/usr/local/lib/python3.9/site-packages/amqp/transport.py", line 564, in _shutdown_transport
    self.sock = self.sock.unwrap()
  File "/usr/local/lib/python3.9/ssl.py", line 1285, in unwrap
    s = self._sslobj.shutdown()
BrokenPipeError: [Errno 32] Broken pipe

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/celery/worker/worker.py", line 203, in start
    self.blueprint.start(self)
  File "/usr/local/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "/usr/local/lib/python3.9/site-packages/celery/bootsteps.py", line 365, in start
    return self.obj.start()
  File "/usr/local/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 326, in start
    blueprint.start(self)
  File "/usr/local/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "/usr/local/lib/python3.9/site-packages/celery/worker/consumer/mingle.py", line 37, in start
    self.sync(c)
  File "/usr/local/lib/python3.9/site-packages/celery/worker/consumer/mingle.py", line 41, in sync
    replies = self.send_hello(c)
  File "/usr/local/lib/python3.9/site-packages/celery/worker/consumer/mingle.py", line 54, in send_hello
    replies = inspect.hello(c.hostname, our_revoked._data) or {}
  File "/usr/local/lib/python3.9/site-packages/celery/app/control.py", line 389, in hello
    return self._request('hello', from_node=from_node, revoked=revoked)
  File "/usr/local/lib/python3.9/site-packages/celery/app/control.py", line 106, in _request
    return self._prepare(self.app.control.broadcast(
  File "/usr/local/lib/python3.9/site-packages/celery/app/control.py", line 741, in broadcast
    return self.mailbox(conn)._broadcast(
  File "/usr/local/lib/python3.9/site-packages/kombu/pidbox.py", line 335, in _broadcast
    self._publish(command, arguments, destination=destination,
  File "/usr/local/lib/python3.9/site-packages/kombu/pidbox.py", line 303, in _publish
    producer.publish(
  File "/usr/local/lib/python3.9/site-packages/kombu/messaging.py", line 177, in publish
    return _publish(
  File "/usr/local/lib/python3.9/site-packages/kombu/connection.py", line 557, in _ensured
    errback and errback(exc, 0)
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/kombu/connection.py", line 451, in _reraise_as_library_errors
    raise ConnectionError(str(exc)) from exc
kombu.exceptions.OperationalError: [Errno 32] Broken pipe
</pre>
t/unit/test_transport.py::test_AbstractTransport_connect::test_close__close_error t/unit/test_transport.py::test_SSLTransport::test_close__unwrap_error
t/unit/test_transport.py::test_socket_options::test_backward_compatibility_tcp_transport t/unit/test_transport.py::test_socket_options::test_backward_compatibility_SSL_transport t/unit/test_transport.py::test_socket_options::test_use_default_sock_tcp_opts t/unit/test_transport.py::test_socket_options::test_set_single_sock_tcp_opt_tcp_transport t/unit/test_transport.py::test_socket_options::test_set_single_sock_tcp_opt_SSL_transport t/unit/test_transport.py::test_socket_options::test_values_are_set t/unit/test_transport.py::test_socket_options::test_passing_wrong_options t/unit/test_transport.py::test_socket_options::test_passing_wrong_value_options t/unit/test_transport.py::test_socket_options::test_passing_value_as_string t/unit/test_transport.py::test_socket_options::test_passing_tcp_nodelay t/unit/test_transport.py::test_socket_options::test_platform_socket_opts t/unit/test_transport.py::test_socket_options::test_set_sockopt_opts_timeout t/unit/test_transport.py::test_AbstractTransport::test_port t/unit/test_transport.py::test_AbstractTransport::test_read t/unit/test_transport.py::test_AbstractTransport::test_setup_transport t/unit/test_transport.py::test_AbstractTransport::test_shutdown_transport t/unit/test_transport.py::test_AbstractTransport::test_write t/unit/test_transport.py::test_AbstractTransport::test_close t/unit/test_transport.py::test_AbstractTransport::test_close_os_error t/unit/test_transport.py::test_AbstractTransport::test_read_frame__timeout t/unit/test_transport.py::test_AbstractTransport::test_read_frame__SSLError t/unit/test_transport.py::test_AbstractTransport::test_read_frame__EINTR t/unit/test_transport.py::test_AbstractTransport::test_read_frame__EBADF t/unit/test_transport.py::test_AbstractTransport::test_read_frame__simple t/unit/test_transport.py::test_AbstractTransport::test_read_frame__long t/unit/test_transport.py::test_AbstractTransport::test_write__success t/unit/test_transport.py::test_AbstractTransport::test_write__socket_timeout t/unit/test_transport.py::test_AbstractTransport::test_write__EINTR t/unit/test_transport.py::test_AbstractTransport::test_having_timeout_none t/unit/test_transport.py::test_AbstractTransport::test_set_timeout t/unit/test_transport.py::test_AbstractTransport::test_set_timeout_exception_raised t/unit/test_transport.py::test_AbstractTransport::test_set_same_timeout t/unit/test_transport.py::test_AbstractTransport::test_set_timeout_ewouldblock_exc t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_socket_fails t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_socket_initialization_fails t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_multiple_addr_entries_fails t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_multiple_addr_entries_succeed t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_short_curcuit_on_INET_succeed t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_short_curcuit_on_INET_fails t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_getaddrinfo_raises_gaierror t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_getaddrinfo_raises_gaierror_once_recovers t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_survives_not_implemented_set_cloexec t/unit/test_transport.py::test_AbstractTransport_connect::test_connect_already_connected t/unit/test_transport.py::test_SSLTransport::test_repr_disconnected t/unit/test_transport.py::test_SSLTransport::test_repr_connected t/unit/test_transport.py::test_SSLTransport::test_setup_transport t/unit/test_transport.py::test_SSLTransport::test_wrap_socket t/unit/test_transport.py::test_SSLTransport::test_wrap_context t/unit/test_transport.py::test_SSLTransport::test_wrap_socket_sni t/unit/test_transport.py::test_SSLTransport::test_wrap_socket_sni_certfile t/unit/test_transport.py::test_SSLTransport::test_wrap_socket_ca_certs t/unit/test_transport.py::test_SSLTransport::test_wrap_socket_ciphers t/unit/test_transport.py::test_SSLTransport::test_wrap_socket_sni_cert_reqs t/unit/test_transport.py::test_SSLTransport::test_wrap_socket_sni_setting_sni_header t/unit/test_transport.py::test_SSLTransport::test_shutdown_transport t/unit/test_transport.py::test_SSLTransport::test_read_EOF t/unit/test_transport.py::test_SSLTransport::test_write_success t/unit/test_transport.py::test_SSLTransport::test_write_socket_closed t/unit/test_transport.py::test_SSLTransport::test_write_ValueError t/unit/test_transport.py::test_SSLTransport::test_read_timeout t/unit/test_transport.py::test_SSLTransport::test_read_SSLError t/unit/test_transport.py::test_TCPTransport::test_repr_disconnected t/unit/test_transport.py::test_TCPTransport::test_repr_connected t/unit/test_transport.py::test_TCPTransport::test_setup_transport t/unit/test_transport.py::test_TCPTransport::test_read_EOF t/unit/test_transport.py::test_TCPTransport::test_read_frame__windowstimeout