Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Zone-aware net.Socket for Node #765

Description

@demurgos

Hi,
I am currently implementing a server-side specific service for my Angular application (using server-side rendering). I am experiencing an issue with calls to the database: the application do not wait for the promise with the DB result to be resolved.
I was able to track down the issue to zone.js not patching the Socket class from Node's net library.
It seems that net.Socket is not patched by zone.js.

Here is a minimal example describing the issue. Both promises resolve to {foo: bar}.
The first one waits for a network packet, the second one uses a timeout.

import * as net from "net";

// The component does not wait for this promise
let p1 = new Promise<{foo: string}>(function (resolve, reject) {
  const s = new net.Socket();
  s.connect(80, "example.com");
  s.write(new Buffer("GET /index.html HTTP/1.1\nHost: example.com\n\n"));
  s.on("data", function(data) {
    resolve({foo: "bar"});
  });
});

// The component waits for this promise
let p2 = new Promise<{foo: string}>(function (resolve, reject) {
  setTimeout(() => resolve({foo: "bar"}), 100);
});

I do not know zone.js very well, but I know that it patches most of the asynchronous functions such as setTimeout, Promises, even Node's EventEmitter and http client so I was surprised that this does not work.

I'll try to learn more about zone.js in the next days to have a better understanding of the issue. In the meantime, is there a workaround ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions