Skip to content

Commit

Permalink
fix: socket case
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Dec 21, 2024
1 parent 821ea82 commit 9f30dd1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/baseFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ export abstract class BaseFramework<
ctxLoggerCache.set(name, ctxLogger);
return ctxLogger;
} else {
const appLogger = this.getLogger(name);
// avoid maximum call stack size exceeded
if (ctx['_logger']) {
return ctx['_logger'];
}
const appLogger = this.getLogger(name);
ctx['_logger'] = this.loggerService.createContextLogger(ctx, appLogger);
return ctx['_logger'];
}
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import {
const debug = util.debuglog('midway:debug');

let stepIdx = 1;
let projectIdx = 1;
function printStepDebugInfo(stepInfo: string) {
debug(`\n\nStep ${stepIdx++}: ${stepInfo}\n`);
debug(`\n\nProject ${projectIdx} - Step ${stepIdx++}: ${stepInfo}\n`);
}

/**
Expand Down Expand Up @@ -139,24 +140,34 @@ export async function initializeGlobalApplicationContext(
export async function destroyGlobalApplicationContext(
applicationContext: IMidwayGlobalContainer
) {

Check failure on line 143 in packages/core/src/setup.ts

View workflow job for this annotation

GitHub Actions / lintAndTestLegacy (lts/*, ubuntu-latest)

Delete `⏎`
printStepDebugInfo('Ready to destroy applicationContext');
const loggerService = await applicationContext.getAsync(MidwayLoggerService);
const loggerFactory = loggerService.getCurrentLoggerFactory();

printStepDebugInfo('Stopping lifecycle');
// stop lifecycle
const lifecycleService = await applicationContext.getAsync(
MidwayLifeCycleService
);
await lifecycleService.stop();

printStepDebugInfo('Stopping applicationContext');
// stop container
await applicationContext.stop();

printStepDebugInfo('Closing loggerFactory');
loggerFactory.close();

printStepDebugInfo('Cleaning performance manager');
MidwayPerformanceManager.cleanAll();

global['MIDWAY_APPLICATION_CONTEXT'] = undefined;
global['MIDWAY_MAIN_FRAMEWORK'] = undefined;

// reset counter
stepIdx = 1;
projectIdx++;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions packages/socketio/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ describe('/test/index.test.ts', () => {
port: 3000,
});

await new Promise<void>(async (resolve, reject) => {
const promise = new Promise<void>((resolve) => {
client.on('connect_error', err => {
console.log(err);
resolve();
});
client.send('my', 1, 2, 3);
await closeApp(app);
});

})
client.send('my', 1, 2, 3);
await Promise.all([closeApp(app), promise]);
await client.close();
});

Expand Down

0 comments on commit 9f30dd1

Please sign in to comment.