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

fix: registerRTT would break successful queries #610

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## To Be Released...
## 5.X.Y
* Added Vintage Story support via the master server (#606)
* Fixed `registerRtt` breaking successful queries if it didn't respond in the query timeout (#610)
* Added support for rFactor 2 (By @xCausxn #614)

## 4.3.2
Expand Down
25 changes: 11 additions & 14 deletions protocols/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,17 @@ export default class Core extends EventEmitter {
async run (/** Results */ state) {}

/** Param can be a time in ms, or a promise (which will be timed) */
async registerRtt (param) {
try {
if (param instanceof Promise) {
const start = Date.now()
await param
await this.registerRtt(Date.now() - start)
} else {
this.logger.debug(`Registered RTT: ${param}ms`)
if (this.shortestRTT === 0 || param < this.shortestRTT) {
this.shortestRTT = param
}
registerRtt (param) {
if (param instanceof Promise) {
const start = Date.now()
param.then(() => {
this.registerRtt(Date.now() - start)
}).catch((_) => {})
} else {
this.logger.debug('Registered RTT: ' + param + 'ms')
if (this.shortestRTT === 0 || param < this.shortestRTT) {
this.shortestRTT = param
}
} catch (error) {
this.logger.debug(`Error in promise: ${error}`)
}
}

Expand Down Expand Up @@ -198,7 +195,7 @@ export default class Core extends EventEmitter {
socket.on('ready', resolve)
socket.on('close', () => reject(new Error('TCP Connection Refused')))
})
await this.registerRtt(connectionPromise)
this.registerRtt(connectionPromise)
connectionTimeout = Promises.createTimeout(this.options.socketTimeout, 'TCP Opening')
await Promise.race([
connectionPromise,
Expand Down
Loading