-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
Adding close method to AuditLogger to free up resources. #1292
Conversation
@@ -172,15 +207,27 @@ export class AuditLogger implements IAuditLogger { | |||
|
|||
private async _getOrSetStreamingDestinations(event: AuditEvent) { | |||
const orgId = event.context.site?.id; | |||
const destinations = await Promise.all([ |
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.
To recreate similar issue just promises just put those lines here and run the DocApi2 test.
new Promise<AuditLogStreamingDestination[] | null>((resolve) => setTimeout(resolve, 10 * 1000, null)),
new Promise<AuditLogStreamingDestination[] | null>((res, reject) => setTimeout(reject, 1, null)),
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.
Thank you!
I just have a suggestion, otherwise looks good to me (but I don't know much this part of the code, so I can't put a seal of quality on that part :)).
app/server/lib/AuditLogger.ts
Outdated
// All log calls should be awaited already and errors should be logged. | ||
await logCall.catch(() => {}); | ||
} | ||
if (this._logsInProgress.length > 0) { |
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.
Right, I understand why you do that: if the logEventOrThrow
method is called while lines 119 to 122 are executed, this should log an error (just like the message suggests). It surprised me a bit (I took some time to understand that despite setting _logsInProgress
to []
, it may still be populated in other places)
But the tests might hang if such a case occur, don't they?
I have an alternative in mind, would it make sense?
- we introduce a boolean property (
_isClosed
for example) which would indicate if theclose
method has been called; - in
logEventOrThrow()
, if the AuditLogger has been closed, we don't even call the internal method_logEventOrThrow
and rather log the message below. This way, nothing is done and we don't have to worry about what happens in this case anyway.
@@ -12,9 +12,6 @@ describe('ColumnOps.ntest', function() { | |||
await gu.supportOldTimeyTestCode(); | |||
await gu.useFixtureDoc(cleanup, "World.grist", true); | |||
await gu.toggleSidePanel('left', 'close'); | |||
// The banner appearing mid-test occasionally interferes with the rest of | |||
// the tests (for some unknown reason), so wait for it to appear first. | |||
await $('.test-banner-element').wait(); |
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 banner was only shown on internal CLI (probably), we will sort it differently.
8baeec2
to
f30279b
Compare
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, with a suggestion! (for what it's worth)
app/common/delay.ts
Outdated
/** | ||
* Returns a promise that resolves in the given number of milliseconds. | ||
* (A replica of bluebird.delay using native promises.) | ||
*/ | ||
export function delay(msec: number): Promise<void> { | ||
return new Promise<void>((resolve) => setTimeout(resolve, msec)); | ||
} | ||
|
||
export async function waitToPass(fn: () => MaybePromise<any>, maxWaitMs: number = 2000) { |
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.
Hmm. A bit unusual to put a test-only method in app? But given that there's nowhere very obvious in tests to put a common library, I guess that's ok. Can you add some documentation about what the method is for (I know there's already undocumented copies of the function lying around, but we should have a higher standard for app/common).
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.
You're right. Turned out we already have it, so I refactored the old one a bit.
app/common/delay.ts
Outdated
await delay(10); | ||
} | ||
} | ||
await fn(); |
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.
Can you add a little note that this is to throw a meaningful error if the fn
isn't passing, rather than just for example saying the timeout failed.
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.
Refactored it to make it more obvious what is going on - and it doesn't need a comment now.
@@ -960,6 +960,7 @@ export class FlexServer implements GristServer { | |||
// Do this after _shutdown, since DocWorkerMap is used during shutdown. | |||
if (this._docWorkerMap) { await this._docWorkerMap.close(); } | |||
if (this._sessionStore) { await this._sessionStore.close(); } | |||
if (this._auditLogger) { await this._auditLogger.close(); } |
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.
Thinking about what happens if there are slow audit sinks and this close takes time. Not much we can do. We could have started the close earlier, in parallel with other actions - but perhaps we want to audit those :).
Let's leave it so.
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 will go away with jobs. Then we would just abort it, and resume later.
757a779
to
6840680
Compare
Sorry for the additional code, there were two additional problems:
|
bbf58d9
to
6de01d5
Compare
Last commit was just a rebase. |
Context
During
DocApi2
server tests we noticed that the mocha process hangs on some resources.Proposed solution
AuditLogger class had two issues which are now fixed:
Promise.all
) where awaitedHas this been tested?