# MessageBus short polling is not working

**URL:** https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508
**Category:** Bug
**Created:** [September 21, 2017, 1:02pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508 "2017-09-21T13:02:38Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [September 21, 2017, 1:02pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/1 "2017-09-21T13:02:38Z")

</div>

We’ve been having some upload issues on our Discourse instance recently: most of the time, if you upload an image it will never finish. Occasionally it will, but only after a lengthy wait.

After doing some investigation, it seems to be down to a problem with MessageBus. If I subscribe to the `/uploads/composer` channel on the server, I’ll get a message containing a working url almost as soon as I’ve clicked upload. The message will usually never get to the client.

This doesn’t just affect uploads, but seemingly all MessageBus channels. Post edits won’t appear before a refresh, and if I subscribe to a test channel I create on the client and push messages to it from the server they won’t arrive.

The one scenario where messages _will_ arrive (more often than not) is if I have two discourse tabs open - when I switch to the second tab, the message will arrive in the first tab.

This is definitely a misconfiguration we have on [discourse.mozilla.org](http://discourse.mozilla.org) - as uploads are working fine here - but I’m not sure what it could be. We only put static assets behind a CDN, and dynamic content is behind ELB and HAProxy - but we’ve changed none of that since we’ve started seeing issues.

Anyone got an idea what could be going on here? I’m pretty stumped… 🌳

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [September 21, 2017, 1:15pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/2 "2017-09-21T13:15:54Z")

</div>

Noted your long polling events are completing almost immediately ~140ms

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/4/24a12d9cd51dc3cc9ee98ab61e4e2284669d4b77.png)

Compared with ~25s here at meta:

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/e/ee9100526be9e1c06e07b7d675630f8d900c3706.png)

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [September 21, 2017, 2:15pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/3 "2017-09-21T14:15:00Z")

</div>

What’s the value of the site setting `long polling base url`?  
Did you configure anything special in ELB and HAProxy regarding Message Bus / long polling?

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [September 21, 2017, 2:33pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/4 "2017-09-21T14:33:47Z")

</div>

Everything under `/admin/site_settings/category/developer` is set to default, apart from `enable long polling`. That was set to false back in 2016 (well before we started seeing this issue), so as expected enabling it didn’t make any difference.

> [@fefrei](#):
>
> What’s the value of the site setting long polling base url?

So, `long polling base url` is the default of `/`.

> [@fefrei](#):
>
> Did you configure anything special in ELB and HAProxy regarding Message Bus / long polling?

No, we’re using the default configuration.

> [@DeanMarkTaylor](#):
>
> Noted your long polling events are completing almost immediately ~140ms

Bizarre… `long polling interval` is set to the default of `25000`.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [September 21, 2017, 3:45pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/5 "2017-09-21T15:45:11Z")

</div>

Not that I have much experience in this specific problem, but some thoughts…

Depending on your AWS ELB setup you might be falling into the “Full site CDN acceleration” category.  
This depends on settings etc at many levels before you get to Discourse, ALB, NLB or Classic Load Balancer might make a difference.

> [@Full site CDN acceleration for Discourse](https://meta.discourse.org/t/full-site-cdn-acceleration-for-discourse/21467):
>
> [Fastly](http://www.fastly.com/) , [CloudFlare](https://www.cloudflare.com) and a few other CDNs offer a mode where they accelerate dynamic content. In a nutshell you point your domain IP address at the CDN and the CDN will intelligently decide how to deal with the request. Static content can be easily served from cache Dynamic content can be routed to the site. This provides some advantages over only shipping static assets which is covered in [the CDN howto](https://meta.discourse.org/t/enable-a-cdn-for-your-discourse/14857). You can elect for “[shielding](http://www.fastly.com/products/origin-shield/)” that protects your site from traffic spikes. Dynamic cont…

Specifically point you at rule number one:

> [@Full site CDN acceleration for Discourse](https://meta.discourse.org/t/full-site-cdn-acceleration-for-discourse/21467/1):
>
> If you enable full site acceleration with a CDN it is critical you follow 3 rules
> 
> 1. The “message bus” must be served from the origin.
> 2. You need to set up X-Forwarded-For trust. For Cloudflare, add cloudflare.template.yml to your app.yml file.
> 3. Be extra careful with techniques that apply optimisation to the site, stuff like Rocket Loader can stop Discourse from working. Discourse is already heavily optimised, this is not needed.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 21, 2017, 3:55pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/6 "2017-09-21T15:55:52Z")

</div>

This looks like a bug in message bus short polling to me, you are subscribing on -1 but not getting the position in the channel like you should. You really should fix long polling cause its really inefficient the way you have it going, but regardless bugs in short polling are no good so we should fix them.

Added to my list and will look at adding some tests for this next week.

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [September 21, 2017, 4:44pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/7 "2017-09-21T16:44:46Z")

</div>

> [@DeanMarkTaylor](#):
>
> Depending on your AWS ELB setup you might be falling into the “Full site CDN acceleration” category.

I don’t think we are. @yousef assures me that every request to [discourse.mozilla.org](http://discourse.mozilla.org) will always hit the docker container. Neither ELB nor HAProxy will ever fetch from a cache instead.

> [@sam](#):
>
> You really should fix long polling cause its really inefficient the way you have it going

Totally up for that, but I’m not sure I even understand how long polling is broken. What would cause Discourse to use short polling over long polling, like it is on [discourse.mozilla.org](http://discourse.mozilla.org)?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 21, 2017, 5:12pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/8 "2017-09-21T17:12:29Z")

</div>

> [@LeoMcA](#):
>
> What would cause Discourse to use short polling over long polling

enable long polling being set to false perhaps some proxy running http 1.0 ? I really don’t know need to know the exact design you have and all the site settings.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [September 21, 2017, 5:14pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/9 "2017-09-21T17:14:22Z")

</div>

> [@DeanMarkTaylor](#):
>
> Depending on your AWS ELB setup you might be falling into the “Full site CDN acceleration” category.

> [@LeoMcA](#):
>
> I don’t think we are.

Well, what I mean by that is there are settings you might need to configure / might not have control over.

For example there is the lovely 60 second default timeout for ELB:

> **[HTTP connections - How Elastic Load Balancing works - Elastic Load Balancing](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html#http-connections)**
>
> A load balancer accepts incoming traffic from clients and routes requests to its registered targets (such as EC2 instances) in one or more Availability Zones. The load balancer also monitors the health of its registered targets and ensures that it...

> You can set an idle timeout value for both Application Load Balancers and Classic Load Balancers. The default value is 60 seconds. With an Application Load Balancer, the idle timeout value applies only to front-end connections. With a Classic Load Balancer, if a front-end connection or a back-end connection is idle for longer than the idle timeout value, the connection is torn down and the client receives an error response. A registered target can use a keep-alive timeout to keep a back-end connection open until it is ready to tear it down.
> 
> Application Load Balancers and Classic Load Balancers support pipelined HTTP on front-end connections. They do not support pipelined HTTP on back-end connections.

---

<div class="post-metadata">

### Author: ![grahamperrin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grahamperrin/32/71406_2.png) [@grahamperrin](https://meta.discourse.org/u/grahamperrin)
#### Post date: [September 22, 2017, 1:16am UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/10 "2017-09-22T01:16:07Z")

</div>

@LeoMcA and all: thank you.

* * *

Cross references:

[https://matrix.to/#/!EIfzkjZqlOZlFzvuWj:matrix.org/$15042507233254388CnwUE:matrix.org](https://matrix.to/#/!EIfzkjZqlOZlFzvuWj:matrix.org/$15042507233254388CnwUE:matrix.org) (2017-09-01):

> Yesterday and today I have sporadic trouble with Firefox drag and drop of images to Discourse. Typically apparently stuck at:
> 
> > Uploading 100%
> 
> …

– and:

[https://github.com/mozilla/discourse/issues/96](https://github.com/mozilla/discourse/issues/96)

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [September 27, 2017, 4:44pm UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/11 "2017-09-27T16:44:00Z")

</div>

Long polling seems to have magically started working again:

 ![Screenshot from 2017-09-27 17-36-49](https://global.discourse-cdn.com/meta/original/3X/9/5/956dd9b4c7400bbc415196b63b1ce51a02b04652.png)

…and with it uploads and edits. ¯\_(ツ)\_/¯

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 29, 2017, 7:01am UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/12 "2017-09-29T07:01:09Z")

</div>

For what it is worth I just fixed up the issues in message bus per:

> <https://github.com/discourse/discourse/commit/41261b32a5099b7e2b87bdc96351cf067d09819a>
>
> \- Corrects broken short polling
> \- Corrects after fork

> <https://github.com/discourse/message_bus/commit/0664af8b4cfb395b47c3f3b669a874b44d073957>

Great catch … moving this to #Contribute > Bug and closing!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 29, 2017, 7:01am UTC](https://meta.discourse.org/t/messagebus-short-polling-is-not-working/70508/13 "2017-09-29T07:01:31Z")

</div>


