Skip to content

ioctl(2) failed exception #220

Closed
Closed

Description

@Tyriar

Maybe the pty has already been destroyed?

Stack 
Error: ioctl(2) failed.
at UnixTerminal.resize (/node_modules.asar/node-pty/lib/unixTerminal.js:227:13)
/vs/workbench/parts/terminal/node/terminalProcess.ts#123:19 (resize)
/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts#158:17 (setDimensions)
/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts#999:72 (onComplete)
/vs/base/common/winjs.base.js#1191:0 (_notify)
/vs/base/common/winjs.base.js#867:0 (enter)
/vs/base/common/winjs.base.js#1089:0 (_run)
/vs/base/common/winjs.base.js#1057:0 (c)
/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts#63:4 (call)
/vs/base/common/event.ts#140:15 (fire)
/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts#132:24 (call)
/vs/base/common/event.ts#140:15 (fire)
/vs/workbench/parts/terminal/node/terminalProcess.ts#104:25 (_sendProcessId)
/vs/workbench/parts/terminal/node/terminalProcess.ts#69:8

VS Code issue: microsoft/vscode#57976

Activity

  1. added
    bug
    help wanted
    on Sep 5, 2018
  2. jerch commented on Sep 5, 2018

    @jerch
    Collaborator

    Daniel Imms (@Tyriar):
    Hard to say, this error will be thrown whenever the file descriptor fd is invalid: https://github.com/Microsoft/node-pty/blob/1c3cd4710c48ad45615da562d10d76162ad43c39/src/unix/pty.cc#L368

    Possible reasons:

    • fd is something else (not a pty master at all)
    • pty already closed and fd is stale
    • fd number got reattched to something else (e.g. some other file)

    Any more info when this exactly happens?

    Might be useful to output errno to see the actual error.

  3. Tyriar commented on Sep 10, 2018

    @Tyriar
    ContributorAuthor

    No more info unfortunately, these are just errors that we're seeing in the wild.

  4. Tyriar commented on May 1, 2019

    @Tyriar
    ContributorAuthor

    I don't see how this could happen atm as this._fd is synchronously in the ctor and resize must have been called after it, but the repro in microsoft/vscode#71078 seems to indicate that resizing again will fix it.

  5. added this to the milestone on May 1, 2019
  6. removed
    help wanted
    on May 1, 2019
  7. removed this from the milestone on May 1, 2019
  8. added
    help wanted
    on May 1, 2019
  9. removed their assignment
    on May 1, 2019
  10. Tyriar commented on May 1, 2019

    @Tyriar
    ContributorAuthor

    Adding a better error that should reveal why the call failed in #285

  11. Tyriar commented on Dec 19, 2025

    @Tyriar
    ContributorAuthor

    Experience on Windows/conpty:

    > const a = require('.')
    undefined
    > const b = a.spawn('cmd.exe')
    undefined
    > b.resize(10, 10)
    undefined
    > b.kill()
    undefined
    > b.resize(10, 10)
    Uncaught Error: Cannot resize a pty that has already exited
        at WindowsPtyAgent.resize (C:\Github\microsoft\node-pty\lib\windowsPtyAgent.js:121:23)
        at WindowsTerminal.<anonymous> (C:\Github\microsoft\node-pty\lib\windowsTerminal.js:130:26)
        at WindowsTerminal._deferNoArgs (C:\Github\microsoft\node-pty\lib\windowsTerminal.js:161:24)
        at WindowsTerminal.resize (C:\Github\microsoft\node-pty\lib\windowsTerminal.js:129:14)
    

    if (this._exitCode !== undefined) {
    throw new Error('Cannot resize a pty that has already exited');
    }

  12. Tyriar commented on Dec 19, 2025

    @Tyriar
    ContributorAuthor

    mac:

    > b.resize(10, 10)
    Uncaught Error: ioctl(2) failed, EBADF
        at UnixTerminal.resize (/Users/tyriar/dev/microsoft/node-pty/lib/unixTerminal.js:253:13)
    

    We pass through the error here:

    node-pty/src/unix/pty.cc

    Lines 522 to 534 in d2d8fd3

    if (ioctl(fd, TIOCSWINSZ, &winp) == -1) {
    switch (errno) {
    case EBADF:
    throw Napi::Error::New(env, "ioctl(2) failed, EBADF");
    case EFAULT:
    throw Napi::Error::New(env, "ioctl(2) failed, EFAULT");
    case EINVAL:
    throw Napi::Error::New(env, "ioctl(2) failed, EINVAL");
    case ENOTTY:
    throw Napi::Error::New(env, "ioctl(2) failed, ENOTTY");
    }
    throw Napi::Error::New(env, "ioctl(2) failed");
    }

    This is good enough for now as it's easy to look up what the error means.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions