Skip to content

Commit 89a5b12

Browse files
committed
Fix for flakiness in socket tests. NFC (emscripten-core#23103)
In emscripten-core#22987 I added a new veriant of the test_nodejs_sockets_echo test and chose the next consecutive port number, but it seems that each test ends up using two ports numbers so this could conflicted with the tests that were using both the previous and next number in the sequence (59164 and 59166).
1 parent f23c8d4 commit 89a5b12

6 files changed

+24
-19
lines changed

src/library.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ addToLibrary({
128128
if (keepRuntimeAlive() && !implicit) {
129129
var msg = `program exited (with status: ${status}), but keepRuntimeAlive() is set (counter=${runtimeKeepaliveCounter}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;
130130
#if MODULARIZE
131-
readyPromiseReject(msg);
131+
if (!runtimeInitialized) {
132+
// If the runtime has not yet been initializated then reject the
133+
// ready promise instead of logging the error here.
134+
readyPromiseReject(msg);
135+
} else
132136
#endif // MODULARIZE
133137
err(msg);
134138
}

src/postamble.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,21 @@ function run() {
163163

164164
#if WASM_WORKERS
165165
if (ENVIRONMENT_IS_WASM_WORKER) {
166+
initRuntime();
166167
#if MODULARIZE
167168
readyPromiseResolve(Module);
168-
#endif // MODULARIZE
169-
return initRuntime();
169+
#endif
170+
_wasmWorkerInitializeRuntime();
171+
return;
170172
}
171173
#endif
172174

173175
#if PTHREADS
174176
if (ENVIRONMENT_IS_PTHREAD) {
177+
initRuntime();
175178
#if MODULARIZE
176-
// The promise resolve function typically gets called as part of the execution
177-
// of `doRun` below. The workers/pthreads don't execute `doRun` so the
178-
// creation promise can be resolved, marking the pthread-Module as initialized.
179179
readyPromiseResolve(Module);
180-
#endif // MODULARIZE
181-
initRuntime();
180+
#endif
182181
startWorker(Module);
183182
return;
184183
}
@@ -208,14 +207,14 @@ function run() {
208207
if (ABORT) return;
209208

210209
initRuntime();
210+
#if MODULARIZE
211+
readyPromiseResolve(Module);
212+
#endif
211213

212214
#if HAS_MAIN
213215
preMain();
214216
#endif
215217

216-
#if MODULARIZE
217-
readyPromiseResolve(Module);
218-
#endif
219218
#if expectToReceiveOnModule('onRuntimeInitialized')
220219
Module['onRuntimeInitialized']?.();
221220
#endif

src/preamble.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function initRuntime() {
215215
runtimeInitialized = true;
216216

217217
#if WASM_WORKERS
218-
if (ENVIRONMENT_IS_WASM_WORKER) return _wasmWorkerInitializeRuntime();
218+
if (ENVIRONMENT_IS_WASM_WORKER) return;
219219
#endif
220220

221221
#if PTHREADS
@@ -471,11 +471,13 @@ function abort(what) {
471471
var e = new WebAssembly.RuntimeError(what);
472472

473473
#if MODULARIZE
474-
readyPromiseReject(e);
474+
if (!runtimeInitialized) {
475+
// If the runtime has not yet been initializated then reject the
476+
// ready promise instead of thowing the error;
477+
readyPromiseReject(e);
478+
return;
479+
}
475480
#endif
476-
// Throw the error whether or not MODULARIZE is set because abort is used
477-
// in code paths apart from instantiation where an exception is expected
478-
// to be thrown when abort is called.
479481
throw e;
480482
}
481483

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
54928
1+
54737
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
30574
1+
30383
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53724
1+
53533

0 commit comments

Comments
 (0)