-
Couldn't load subscription status.
- Fork 334
Share getThreadManager pool among RuntimeServerInstrument and Websocket emulation
#12528
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
Conversation
Manual TestingLet's use a simple script that connects to echo service at http://websocket.org to verify how well the support for var counter = 0;
function app() {
print("Connecting to websocket.org...");
let ws = new WebSocket('wss://echo.websocket.org');
function sayHi() {
ws.send(`Hi there! #${counter++}`);
}
ws.onopen = function(ev) {
print("Open: " + ev);
};
ws.onmessage = function(ev) {
print("Msg : " + Object.getOwnPropertyNames(ev));
print(" data: " + ev.data);
setTimeout(sayHi, 3000);
};
ws.onclose = function(ev) {
print("Close: " + Object.getOwnPropertyNames(ev));
};
ws.onerror = function(ev) {
print("Err: " + Object.getOwnPropertyNames(ev));
};
}
if (typeof insight === "undefined") {
globalThis.print = console.log;
if (typeof WebSocket === "undefined") {
let r = require("ws");
globalThis.WebSocket = r.WebSocket;
}
app();
} else {
app();
}The script is generic. You can use it in node.js as well as Enso IDE or command line interface. Enso GUIStore the above script as enso$ export ENSO_JVM_OPTS="-Denso.dev.insight=/tmp/wstest.js -Dpolyglot.enso.interpreter.jobParallelism=1"
enso$ sbt runProjectManagerDistribution
....
Connecting to websocket.org...
...
Msg :
data: Hi there! #2
...and in another terminal execute Verify with node.jsSave the above script into an empty directory and so on. Every few seconds another "Hi there!" message with an increased counter shall appear. The same output shall be visible in the Enso GUI as well as from CLI. |
|
@hubertp, @4e6, do you think following assumption:
Is supposed to be true? E.g. if I fix the violations and set Update on Apr 10, 2025:
|
lib/java/ydoc-polyfill/src/main/java/org/enso/ydoc/polyfill/web/WebSocket.java
Outdated
Show resolved
Hide resolved
...er/src/main/java/org/enso/interpreter/instrument/runtime/server/RuntimeServerInstrument.java
Outdated
Show resolved
Hide resolved
engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/EpbContext.java
Outdated
Show resolved
Hide resolved
getThreadManager pool among RuntimeServerInstrument and Websocket emulation
|
We seem to have problems with shutdown: probably the shutdown isn't done properly. |
c9e4fbe to
4cc47eb
Compare
| } | ||
| : null; | ||
| var allDefs = localScope.allSymbols(name, logFnOrNull); | ||
| var allDefs = localScope.allSymbols(name, 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.
b5b430a avoids usage of TruffleLogger from non-guest code threads.
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.
OK
|
|
||
| final void handleMultiAccess(String msg) { | ||
| try { | ||
| var ms = delayer.nextInt(10, 1000); |
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.
shouldn't we log this event always?
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.
- I was thinking about some heuristics to decide when to log, but
- at the end I decided to leave it out of this PR
- I am not sure logging (and dumping all the thread stacks) always is what we want
- there might be plenty of events like this
- a one line note in the log when verbosity is high might be OK
- so far I haven't seen many clashes even I am running with
-eaon
|
Let's merge and continue with |
Pull Request Description
Resolves #11477 by making callbacks from
ydoc-polyfillWebSocketemulation via the sameScheduledExecutorServiceas provided byEnsoLanguage. In addition to that it registersthreadAccessDeniedHandlerto coordinate JavaScript multi threaded execution.Important Notes
The
EpbLanguage(which injects theWebSocketemulation) locates theEnsoLanguageby its ID and obtains a reference toEnsoContext.getThreadManager()vialookup(langInfo, ScheduledExecutorService.class). Then it uses the obtained executor service for making callbacks into JavaScript whenever a websocket event arrives.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,