aRestless

[fixed] Bug: Window reload breaks overwolf.web.webserver

Recommended Posts

Consider the following code snippet:
 

function createWebserver(port, onSuccess) {
    overwolf.web.createServer(port, function(createResult) {
        if (createResult.status === "success") {
            createResult.server.listen(function(listenResult) {
                if (listenResult.status === "success") {
                    onSuccess(port);
                } else {
                    createWebserver(port + 1, onSuccess);
                }
            });
        } else {
            createWebserver(port + 1, onSuccess);
        }
    });
}

createWebserver(44444, function(port) {console.log("Listening on port " + port);});

This attempts to create a webserver listening on port 44444, and if that fails (probably because the port is occupied already), it tries the next port, and so on, until it succeeds.
 
Now if you've got an app with a main window and a subwindow (the main window immediately opens the subwindow), the main window will print out

"Listening on port 44444"

and the subwindow will print out

"Listening on port 44445"

because the main window already occupied port 44444, the allocation there failed, and so the sub window jumps to the next port.
 
However, if you now reload the subwindow, via F5 in the dev console, window.location.reload(), navigator.plugins.refresh(true), anything like that, the subwindow will print out

"Listening on port 44444"

Meaning, it allocated a webserver on a port that was already occupied. That's obviously not possible. And the message on successful allocation is certainly wrong, because all requests to port 44444 still reach the main window, not the sub window.

 

This is not fixable by calling server.close() before reloading. The error will remain. The only way to work around it is, instead of reloading the window, to close it and open it again. A sample app showcasing everything I talked about is attached.

 

This is yet another breaking bug that prevents progress on one of my projects.

 

Cheers,

aRestless

 

OverwolfWebserverBug-1.0.0.zip
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now