Open CMCDragonkai opened 3 months ago
One way to get around this warning is potentially doing all the work in the C++ level? One way to do this is pass the reference to the JS socket object to the native code side, and get the native code to do the necessary referencing of the underlying FD.
Also can we start changing all our native code to Rust to align with js-quic and js-exec? I know js-db is still pending, but it's usually better.
Look at node native code docs as to how to directly interact with socket objects.
If we are only using the net.Socket._handle
to extract the fd
of the socket, can't we just create the socket with a predetermined fd
and reference that wherever we need to?
The new net.Socket()
constructor has an option to specify the fd
. We can use the C++ socketUtils
to find the closest unoccupied file descriptor, and use that while construction, and keep track of that in a Map
or a Record
. We can then later reference that when we need to call disableSocketMulticastAll
.
Doing it this way would be simpler than directly interacting with the actual Socket
object.
https://nodejs.org/api/net.html#new-netsocketoptions
@cmcdragonkai
I'm not really sure what that means. You'd have to try it. But my understanding is that we are creating sockets for this purpose and so using the rust native code is better anyway to align all of our native libraries.
After looking over the source code a bit more, my solution feels more like a temporary patch than a permanent solution. As I couldn't find much information about this online, I asked ChatGPT, and it agreed with you that creating a native binding which manages the entire socket lifetime seems to be the best solution, as no API currently exists which allows us to do the fine-grained multicast manipulation or get the fd
without relying on _handle
.
@aryanjassal i've tried to implement the solution you had suggested originally when working on it in the https://github.com/MatrixAI/js-mdns/tree/feature-remove-warning branch. However, I was not able to successfully get the node socket to correctly attach to the fd of the existing socket. There should be a test written in that repo that demonstrates this behaviour.
If I recall, the socket modification was to avoid some extra logic in the js-mdns
library to handle it. We may just have to do that in the end to resolve this. @amy I don't recall the exact details of this. Can you give a summary of why the socket was modified leading to this warning and what it was trying to avoid in the code. So basically how need to fix this.
Describe the bug
Inside
MDNS.ts
, it's using_handle
in a few places. In particular:The usage of
_handle
in theSocket
prototype causes warnings.It looks like this in PK CLI:
Right after starting the agent.
Find an alternative way to do the above, or we need some way of disabling the warning? This is some sort of internal property right?
Apparently Node allows disabling warnings on startup.
To Reproduce
polykey agent start
Expected behavior
No warnings should occur.
Additional context
Notify maintainers
@amydevs