Skip to content

Commit 2b4c642

Browse files
Fix logs and memory tracking (#82)
## Description <!-- A brief description of what the PR does/changes. Use active voice and present tense, e.g., This PR fixes ... --> This PR fixes how log returned from connector is shown in SDK when skipped and improve memory tracking logging. ## Connected Issues <!-- DevRev issue(s) full link(s) (e.g. https://app.devrev.ai/devrev/works/ISS-123). --> https://app.devrev.ai/devrev/works/ISS-215007 ## Checklist - [x] Tests added/updated and ran with `npm run test` OR no tests needed. - [x] Ran backwards compatibility tests with `npm run test:backwards-compatibility`. - [x] Tested airdrop-template linked to this PR. - [x] Documentation updated and provided a link to PR / new docs OR `no-docs` written: <!-- Add this once we have eslint prepared: - [ ] Code formatted and checked with `npm run lint`. -->
1 parent ac7e6b4 commit 2b4c642

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/attachments-streaming/attachments-streaming-pool.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export class AttachmentsStreamingPool<ConnectorState> {
123123

124124
if (response?.error) {
125125
console.warn(
126-
`Skipping attachment with ID ${attachment.id} due to error: ${response.error}`
126+
`Skipping attachment with ID ${attachment.id} due to error returned by the stream function`,
127+
response.error
127128
);
128129
await this.updateProgress();
129130
continue;
@@ -142,7 +143,8 @@ export class AttachmentsStreamingPool<ConnectorState> {
142143
await this.updateProgress();
143144
} catch (error) {
144145
console.warn(
145-
`Skipping attachment with ID ${attachment.id} due to error: ${error}`
146+
`Skipping attachment with ID ${attachment.id} due to error in processAttachment function`,
147+
error
146148
);
147149

148150
await this.updateProgress();

src/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ export const LIBRARY_VERSION = getLibraryVersion();
6969

7070
export const DEFAULT_LAMBDA_TIMEOUT = 10 * 60 * 1000; // 10 minutes
7171
export const HARD_TIMEOUT_MULTIPLIER = 1.3;
72-
export const MEMORY_LOG_INTERVAL = 10 * 1000; // 10 seconds
72+
export const MEMORY_LOG_INTERVAL = 30 * 1000; // 30 seconds
7373

7474
export const DEFAULT_SLEEP_DELAY_MS = 3 * 60 * 1000; // 3 minutes

src/common/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export interface MemoryInfo {
236236
formattedMessage: string;
237237
}
238238

239-
export function getMemoryUsage(): MemoryInfo | null {
239+
export function getMemoryUsage(): MemoryInfo {
240240
try {
241241
const memUsage = process.memoryUsage();
242242
const heapStats = v8.getHeapStatistics();
@@ -274,7 +274,7 @@ export function getMemoryUsage(): MemoryInfo | null {
274274
formattedMessage,
275275
};
276276
} catch (err) {
277-
console.error('Error retrieving memory usage:', (err as Error).message);
278-
return null;
277+
console.warn('Error retrieving memory usage', err);
278+
throw err;
279279
}
280280
}

src/workers/spawn.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,23 @@ export class Spawn {
231231
}
232232
});
233233

234-
// Log memory usage every 10 seconds
234+
// Log memory usage every 30 seconds
235235
this.memoryMonitoringInterval = setInterval(() => {
236-
const memoryInfo = getMemoryUsage();
237-
if (memoryInfo) {
238-
this.logger.info(memoryInfo.formattedMessage);
236+
try {
237+
const memoryInfo = getMemoryUsage();
238+
if (memoryInfo) {
239+
this.logger.info(memoryInfo.formattedMessage);
240+
}
241+
} catch (error) {
242+
// If memory monitoring fails, log the warning and clear the interval to prevent further issues
243+
this.logger.warn(
244+
'Memory monitoring failed, stopping logging of memory usage interval',
245+
error
246+
);
247+
if (this.memoryMonitoringInterval) {
248+
clearInterval(this.memoryMonitoringInterval);
249+
this.memoryMonitoringInterval = undefined;
250+
}
239251
}
240252
}, MEMORY_LOG_INTERVAL);
241253
}
@@ -253,6 +265,8 @@ export class Spawn {
253265
}
254266

255267
private async exitFromMainThread(): Promise<void> {
268+
this.clearTimeouts();
269+
256270
if (this.alreadyEmitted) {
257271
this.resolve();
258272
return;

0 commit comments

Comments
 (0)