-
Notifications
You must be signed in to change notification settings - Fork 295
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(satp-hermes): shutdown of SATP gateway should assure there are no pending transfers before shutting down #3802
base: satp-dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but the method of verifying sessions should done in a different approach.
@@ -308,6 +309,17 @@ export class SATPManager { | |||
return this.satpHandlers.get(type); | |||
} | |||
|
|||
public getSATPSessionState(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document this method
private async verifySessionsState(): Promise<void> { | ||
const fnTag = `${this.className}#verifySessionsState()`; | ||
this.logger.trace(`Entering ${fnTag}`); | ||
if (!this.BLODispatcher) { | ||
throw new Error(`Cannot ${fnTag} because BLODispatcher is erroneous`); | ||
} | ||
this.BLODispatcher.setInitiateShutdown(); | ||
const manager = await this.BLODispatcher.getManager(); | ||
let status = false; | ||
while (!status) { | ||
this.logger.debug(`Inside: ${status}`); | ||
status = await manager.getSATPSessionState(); | ||
if (!status) { | ||
this.logger.info("Sessions are still pending"); | ||
await new Promise(resolve => setTimeout(resolve, 20000)); | ||
} | ||
} | ||
this.logger.info("All sessions are concluded"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a blocker function, change this to use a Cron job:
https://stackoverflow.com/questions/64777543/how-to-make-a-cron-job-for-a-typescript-class-method
@@ -224,6 +224,12 @@ export class SATPSession { | |||
return this.serverSessionData?.id || this.clientSessionData?.id || ""; | |||
} | |||
|
|||
public getSessionState(): State { | |||
console.log("serverSessionId: ", this.serverSessionData?.state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the component logger instead of console.log
this.BLODispatcher.setInitiateShutdown(); | ||
const manager = await this.BLODispatcher.getManager(); | ||
let status = false; | ||
while (!status) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a potential infinite loop. this function might block, and we need to decide if this is desirable behaviour. On one hand, the gateway cannot handle anything else; on the other, it should not serve new requests. So there should be a middle-term that allows the gateway to keep serving other requests (namely admin) while not initiating new transfers nor blocking.
Besides, we might want to include a timeout, since something can be broken in the manager (in particular if there is a hanging SATP transfer, communicating with a counterparty gateway).
Signed-off-by: Joao Pereira <[email protected]>
0c911a2
to
54602e8
Compare
Signed-off-by: Joao Pereira <[email protected]>
Introduces a new function,
verifySessionState
, which upon shutdown verifies if all sessions are concluded. Also a flag was created to prevent new transactions to occur when shutdown was already called.Additionally, a new type of error is introduced
gateway-error
.Resolves #3756.
Pull Request Requirements
upstream/main
branch and squashed into single commit to help maintainers review it more efficient and to avoid spaghetti git commit graphs that obfuscate which commit did exactly what change, when and, why.-s
flag when usinggit commit
command. You may refer to this link for more information.Character Limit
A Must Read for Beginners
For rebasing and squashing, here's a must read guide for beginners.