samchon / tgrid

TypeScript RPC (Remote Procedure Call) for WebSocket and Worker protocols
https://tgrid.com/
MIT License
141 stars 19 forks source link

WorkerConnector.compile can cause disk | memory leak #9

Closed samchon closed 5 years ago

samchon commented 5 years ago

Summary

Code occuring the bug

In NodeJS

https://github.com/samchon/tgrid/blob/ec443a2a8147ff6f5d6f3917cabdbec988fee39b/src/protocols/workers/WorkerConnector.ts#L61-L67

In NodeJS environment, you can see the WorkerConnector.compile() method calls a neighbor WorkerConnector.connect() function. If the WorkerConnector.compile() method throws an exception, then Compiler.remove() cannot be called and it may cause the disk leak.

In Browser

https://github.com/samchon/tgrid/blob/ec443a2a8147ff6f5d6f3917cabdbec988fee39b/src/protocols/workers/WorkerConnector.ts#L69

In Web Browser, WorkerConnector.compile() compiles (creates) a JS file, but does not remove it. Of course, the JS file would be automatically removed when the browser closed, but it seems dangerous. If someone compiles (WorkerConnector.compile()) lots of JS files in a page, then they would be memory leak.

https://github.com/samchon/tgrid/blob/ec443a2a8147ff6f5d6f3917cabdbec988fee39b/src/protocols/workers/internal/web-worker.ts#L9-L13

WorkerConnector.compile() should utilize not only URL.createObject function, but also URL.removeObject function.

samchon commented 5 years ago

In such reason, SharedWorkerConnector also need to have the remove function.

samchon commented 5 years ago

Fixed in v0.1.1 update