title: Celery task does not get send to broker
body: <p>When I try to send my task to broker (RabbitMQ) it hangs.</p>
  <pre class="lang-py prettyprint-override"><code># python shell
  promise = foo.s(first_arg=&quot;2&quot;).apply_async()
  # blocking indefinitely. I expected a promise object.
  </code></pre>
  <p>If I run the task synchronously it works as expected.</p>
  <pre class="lang-py prettyprint-override"><code># python shell
  promise = foo.s(first_arg=&quot;2&quot;).apply()
  &gt;&gt;&gt; hello argument 2
  </code></pre>
  <p>If I interrupt <code>.apply_async()</code> with ctrl+c I get a traceback with some clues:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py&quot;, line 32, in __call__
      return self.__value__
  AttributeError: 'ChannelPromise' object has no attribute '__value__'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/amqp/transport.py&quot;, line 173, in _connect
      host, port, family, socket.SOCK_STREAM, SOL_TCP)
    File &quot;/usr/local/lib/python3.7/socket.py&quot;, line 752, in getaddrinfo
      for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  socket.gaierror: [Errno -9] Address family for hostname not supported
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py&quot;, line 325, in retry_over_time
      return fun(*args, **kwargs)
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/connection.py&quot;, line 866, in _connection_factory
      self._connection = self._establish_connection()
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/connection.py&quot;, line 801, in _establish_connection
      conn = self.transport.establish_connection()
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/transport/pyamqp.py&quot;, line 128, in establish_connection
      conn.connect()
    File &quot;/usr/local/lib/python3.7/site-packages/amqp/connection.py&quot;, line 323, in connect
      self.transport.connect()
    File &quot;/usr/local/lib/python3.7/site-packages/amqp/transport.py&quot;, line 113, in connect
      self._connect(self.host, self.port, self.connect_timeout)
    File &quot;/usr/local/lib/python3.7/site-packages/amqp/transport.py&quot;, line 184, in _connect
      &quot;failed to resolve broker hostname&quot;))
    File &quot;/usr/local/lib/python3.7/site-packages/amqp/transport.py&quot;, line 197, in _connect
      self.sock.connect(sa)
  ConnectionRefusedError: [Errno 111] Connection refused
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;/usr/local/lib/python3.7/site-packages/celery/canvas.py&quot;, line 225, in apply_async
      return _apply(args, kwargs, **options)
    File &quot;/usr/local/lib/python3.7/site-packages/celery/app/task.py&quot;, line 565, in apply_async
      **options
    File &quot;/usr/local/lib/python3.7/site-packages/celery/app/base.py&quot;, line 749, in send_task
      amqp.send_task_message(P, name, message, **options)
    File &quot;/usr/local/lib/python3.7/site-packages/celery/app/amqp.py&quot;, line 532, in send_task_message
      **properties
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/messaging.py&quot;, line 178, in publish
      exchange_name, declare,
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/connection.py&quot;, line 525, in _ensured
      return fun(*args, **kwargs)
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/messaging.py&quot;, line 184, in _publish
      channel = self.channel
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/messaging.py&quot;, line 206, in _get_channel
      channel = self._channel = channel()
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py&quot;, line 34, in __call__
      value = self.__value__ = self.__contract__()
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/messaging.py&quot;, line 221, in &lt;lambda&gt;
      channel = ChannelPromise(lambda: connection.default_channel)
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/connection.py&quot;, line 884, in default_channel
      self._ensure_connection(**conn_opts)
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/connection.py&quot;, line 439, in _ensure_connection
      callback, timeout=timeout
    File &quot;/usr/local/lib/python3.7/site-packages/kombu/utils/functional.py&quot;, line 339, in retry_over_time
      sleep(1.0)
  </code></pre>
  <p>The broker connection string looks like this in the system:</p>
  <pre class="lang-sh prettyprint-override"><code>~$ env | grep BROKER
  CELERY_BROKER=pyamqp://guest@172.23.0.3//
  </code></pre>
  <p>The broker connection string in python:</p>
  <pre class="lang-py prettyprint-override"><code># python shell
  from src.celery import app
  app.pool.connection
  &gt;&gt;&gt; Connection: amqp://guest:**@localhost:5672//
  </code></pre>
  <p>Before you suggest that RabbitMQ is not running, or the connection string is bad; my celery worker (consumer) process is able to connect with the same connection string.</p>
  <pre><code>-------------- celery@f9ab48fc6b63 v5.0.5 (singularity)
  --- ***** -----
  -- ******* ---- Linux-4.15.0-20-generic-x86_64-with-debian-9.12 2021-03-05 07:56:29
  - *** --- * ---
  - ** ---------- [config]
  - ** ---------- .&gt; app:         celery_statst_api:0x7f15b6de0450
  - ** ---------- .&gt; transport:   amqp://guest:**@my-rabbit:5672//
  - ** ---------- .&gt; results:     postgresql://docker:**@pg_db:5432/
  - *** --- * --- .&gt; concurrency: 16 (prefork)
  -- ******* ---- .&gt; task events: OFF (enable -E to monitor tasks in this worker)
  --- ***** -----
   -------------- [queues]
                  .&gt; celery           exchange=celery(direct) key=celery
  
  
  [tasks]
    . foo_task
    . (long list of tasks)
  
  [2021-03-05 07:56:30,564: INFO/MainProcess] Connected to amqp://guest:**@my-rabbit:5672//
  [2021-03-05 07:56:30,581: INFO/MainProcess] mingle: searching for neighbors
  [2021-03-05 07:56:31,622: INFO/MainProcess] mingle: all alone
  [2021-03-05 07:56:31,647: INFO/MainProcess] celery@f9ab48fc6b63 ready.
  </code></pre>
  <p>This is how I connect app/producer to the broker.
  The file celeryconfig.py contains setup for broker url backend, concurrency, etc.</p>
  <pre class="lang-py prettyprint-override"><code># celery_tasks.py
  # imports...
  app = Celery('celery_statst_api')
  app.config_from_object(celeryconfig) # import config file
  
  @app.task(name=&quot;foo&quot;)
  def foo(first_arg: str) -&gt; str:
      print(f&quot;thanks for {first_arg}&quot;)
      return &quot;OK&quot;
  
  </code></pre>