Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulateLatency doesn't go back #570

Closed
endel opened this issue May 7, 2023 · 2 comments
Closed

simulateLatency doesn't go back #570

endel opened this issue May 7, 2023 · 2 comments
Assignees
Labels

Comments

@endel
Copy link
Member

endel commented May 7, 2023

Reported by Cucumba on Discord


Server latency simulation bug as previously mentioned here ⁠🐛│bugs⁠
https://github.com/colyseus/colyseus/blob/0.15/packages/core/src/Server.ts#L239
https://github.com/colyseus/colyseus/blob/0.15/packages/transport/ws-transport/src/WebSocketTransport.ts#L73
https://github.com/colyseus/colyseus/blob/0.15/packages/transport/uwebsockets-transport/src/uWebSocketsTransport.ts#L124
Reason: previous function is being overridden each time when simulateLatency is called, it sets timeout for existing timeout, instead of original function

Here is example:

class Logger {
    log(message) {
        console.log(message)
    }
}

function simulateLatency(milliseconds) {
    const previousLog = Logger.prototype.log
    Logger.prototype.log = function(...args) {
        console.warn(milliseconds)
        setTimeout(() => previousLog.apply(this, args), milliseconds);
    }
}

const logger = new Logger()
logger.log("msg") // no delay

simulateLatency(1000)
logger.log("msg") // delay 1 second

simulateLatency(0)
logger.log("msg") // delay 1 second

simulateLatency(1000)
simulateLatency(1000)
simulateLatency(1000)
logger.log("msg") // delay 4 seconds
@endel endel added the 🐛 bug label May 7, 2023
@endel endel self-assigned this May 7, 2023
@afrokick afrokick mentioned this issue Dec 23, 2023
3 tasks
@afrokick
Copy link
Contributor

I fixed it in #663 + some test cases have been added

@endel
Copy link
Member Author

endel commented Dec 27, 2023

Thank you @afrokick 🎉

@endel endel closed this as completed Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants