Skip to content

dgram: instantiate socket on creation #5496

@Trott

Description

@Trott

In Node 5.7.0 and all currently-supported previous versions, it is possible to try to trigger an exception (EBADF) with code such as this:

var dgram = require('dgram');

var socket = dgram.createSocket('udp4');
socket.setTTL(1);

As @saghul explains in #5023, this is because dgram instantiates the socket lazily with uv_udp_init(). If uv_udp_init_ex() were used instead, then the socket could be created and ready for the various .set* functions upon creation.

Such a change would probably be semver-major because createSocket() might throw whereas currently that is not the case.

There are probably loads of other dangers and considerations. (I'm opening this issue so that the discussion can be had independently of the PR linked above, which is a relatively minor and safe change to a test file. This, on the other hand, would be a much bigger deal...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    dgramIssues and PRs related to the dgram subsystem / UDP.libuvIssues and PRs related to the libuv dependency or the uv binding.semver-majorPRs that contain breaking changes and should be released in the next major version.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions