Kurento / bugtracker

[ARCHIVED] Contents migrated to monorepo: https://github.com/Kurento/kurento
46 stars 10 forks source link

Remove improper use of promises in Kurento Javascript client implementation. #181

Open dkushner opened 7 years ago

dkushner commented 7 years ago

Client libraries

Browsers tested

System description: KMS in a Docker container and signal server running on the local machine.

What steps will reproduce the problem?

  1. Import kurento-client package into a browser context.
  2. Create a new, standard Promise and within this context...
  3. Call `kurento(URI, (err, client) => {}) to create a client. Resolve the current promise with the client returned by this method.
  4. Attempt to await the Promise created in step 2.

What is the expected result? The promise resolves, yielding the client object at the await call site.

What happens instead? The promise never resolves because the client object itself is extended from a Promise and so the native Promise implementation assumes it is still waiting on the chain, calls client.then() which just seems to yield client and so we are caught in an endless loop where the promise never resolves.

Does it happen with one of the tutorials? No, the tutorials use incredibly verbose and unnecessary nested callbacks rather than any standard Promise implementations.

Please provide any additional information below. Promises should almost never be extended by shared objects. I've looked through the client code and I still can't make heads or tails of why this was actually done in the first place. Seems to be some attempt to ensure connectedness during construction?

waifutech commented 7 years ago

Wasted A LOT of time figuring out what was happening. This thing is like #define true false.

virtualfunction commented 7 years ago

Is there any intermediate workaround for this?