Context cancelled when Webpack HMR sends updates (FIX)

Hi - I have identified the root cause + a caddyfile fix for a pervious help request - The original thread has now been closed, but it ranks well on Google for this specific issue - and I’d like to help the next person who comes along.

The original thread is:

Long story short
Webpack uses chunked encoding, which gets cancelled by Caddy when buffering is being used.

Fix:
In your caddyfile, specify:

flush_interval -1

As part of your reverse_proxy directive, and hot refresh/hot module reload will work.

(Sorry for skipping the template, not sure how else to submit a fix/solution to an old thread.)

Cheers,
Matt

1 Like

Nice, thanks for posting this! It’s not obvious to someone like me who has no knowledge of or experience with Webpack HMR, but it makes sense that flushing immediately could cause some clients to behave differently in such a way that those log emissions are reduced/eliminated.

This could/should probably be a wiki article if you’re willing to expand or explain it a bit more!

I wonder if @xnaas has tried this as it seems like it might be the right way to eliminate the “log spam” he’s been experiencing, if the plex client is anything similar to Webpack HMR: https://www.reddit.com/r/PleX/comments/iu50ho/plex_and_caddy_v2_reverse_proxy_log_spam/

Thanks for following up on that issue, I added a comment at the end of the thread pointing to here:

Doesn’t seem to be working :\

run: adapting config using caddyfile: Caddyfile:16: unrecognized directive: flush_interval

this is how the file looks like:

{
  auto_https off
}

(theheaders) {
  header Host {host}
  header X-Forwarded-For {remote_host}
  header X-Forwarded-Proto {scheme}
  header X-Url-Scheme {scheme}
  header X-Forwarded-Host {host}
}

localhost:80 {
  import theheaders

  flush_interval -1
  
  root * /home/user/Coding/proj

  route /api* {
  	reverse_proxy localhost:8000
  }
  route /media* {
  	reverse_proxy localhost:8000
  }
  route /admin* {
  	reverse_proxy localhost:8000
  }
  route /static* {
  	reverse_proxy localhost:8000
  }
 route /timeline* {
 	file_server
 }
   reverse_proxy localhost:3000
}

this is Caddy 2.1.1

nvm I should have written this instead:

reverse_proxy localhost:3000 {
  flush_interval -1
}
1 Like

I could’ve sworn I’d tried something similar to this previously, but it may have been putting it in the wrong spot as well…d’oh! After implementing this, the specific message I saw being spammed tons has pretty much disappeared. Good to know the equivalent to proxy_buffering off; from nginx. :+1:t2:

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.