Skip to content

Commit

Permalink
Merge pull request #56 from unyt-org/fix-self-subscribe
Browse files Browse the repository at this point in the history
Fix self subscribing to pointers
  • Loading branch information
benStre authored Jan 21, 2024
2 parents fb2e23d + 63b574e commit 32a8777
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions runtime/pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,13 @@ export class Pointer<T = any> extends Ref<T> {
}

const endpoint = override_endpoint ?? this.origin;

// early return, trying to subscribe to the own main endpoint, guaranteed to be routed back to self, which is not allowed
if (endpoint.equals(Runtime.endpoint.main)) {
logger.warn("tried to subscribe to own pointer: " + this.idString() + "(pointer origin: " + this.origin + ", own endpoint instance: " + Runtime.endpoint + ")");
return this;
}

// logger.debug("subscribing to " + this.idString() + ", origin = " + this.origin + (this.origin!=endpoint ? ", requesting from: " + endpoint : '') + ', get value: ' + get_value);
if (this.origin==endpoint) logger.debug `subscribing to #color(65, 102, 238)${this.idString()}, origin: ${this.origin.toString()}${get_value?', getting value':''}`
else logger.debug `subscribing to #color(65, 102, 238)${this.idString()}, origin: ${this.origin.toString()}, request: ${endpoint.toString()}${get_value?', getting value':''}`
Expand Down
3 changes: 2 additions & 1 deletion runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,7 @@ export class Runtime {

// remote pointer value was set - handle subscription
if (!ptr.is_origin) {

// subscription was already added by pointer origin for preemptively loaded pointer, just finalize
if (isInit) {
ptr.finalizeSubscribe()
Expand Down Expand Up @@ -7305,4 +7306,4 @@ Type.get("std:Iterator").setJSInterface({
visible_children: new Set(['val', 'next']),
})

// displayClear();
// displayClear();

0 comments on commit 32a8777

Please sign in to comment.