webpack-contrib / webpack-hot-middleware

Webpack hot reloading you can attach to your own server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EventSource does not reConnect immediately when Server closes the EventSource

kenkozheng opened this issue · comments

Here is the code in wepack-hot-middleware/client.js
`
function handleDisconnect() {

clearInterval(timer);

source.close();

setTimeout(init, options.timeout);

}
`
Our nodejs server limits 10s timeout for each socket. When socket closes, the client will wait for 20s to reconnect. If we just modify some code during this 20s, nothing will refresh in the browser.

Actually, in the dev mode, just myself use the local server, so there's no need to wait. I guess the meaing of this action is to protect the server.

Please fix this. Just reconnect immediately. All will work well.

`
function handleDisconnect() {

clearInterval(timer);

source.close();

init();

// setTimeout(init, options.timeout);

}
`

Thanks, I know the timeout option. But I don't think it's a good idea to modify it to be 5s or less. It will cause the client to reconnect every 5s even I don't modify anything.
And the server, it's much more harder to modify, because the server is a framework supported by other team, and it's a server for online users.

So, to be convenient, I just modify the code of hot-middleware.

Would you please tell me why wait for 20s to reconnect?

I’m confused. Why would you not use the config option designed to do exactly this?

The reason the timeout is there is because normally people’s connections stay active, so the disconnect only happens in an unusual circumstance. The timeout gives the system time to recover before the client tries again.

If you want the reconnect to happen faster, then use the configuration option to make it happen faster. In your case you could easily set it to 1 second and everything would be fine.

image

Because of this retry logic.

The server is used for online serving, so they design that every socket should be closed within 2 minutes.

I think that dev-middleware server is just serving ourself, so there is no need to wait for it to recover.

But you are right, if the server is shut down, retry immediately will cause some error log in the browser console.