Xterm.js: TypeError: Cannot read property '_data' of undefined

Created on 9 Feb 2019  路  18Comments  路  Source: xtermjs/xterm.js

While resizing the terminal smaller, the following exception occurs. It's not clear exactly how to reproduce. I cat the content of a file and then resize the terminal to a small size:

Uncaught TypeError: Cannot read property '_data' of undefined
    at BufferLine.copyCellsFrom (xterm.js:887)
    at Buffer._reflowSmaller (xterm.js:468)
    at Buffer._reflow (xterm.js:388)
    at Buffer.resize (xterm.js:370)
    at BufferSet.resize (xterm.js:1140)
    at Terminal.resize (xterm.js:5078)
    at Terminal.resize (xterm.js:6615)
    at resize (kubebox.js:1351)
    at Item.run (kubebox.js:52341)
    at drainQueue (kubebox.js:52311)

Details

  • Browser and browser version: Chrome 69
  • OS version: Mac OS X
  • xterm.js version: 3.11.0

Steps to reproduce

  1. Resize the terminal smaller
typbug

Most helpful comment

I released 3.12.1 that includes just this fix https://github.com/xtermjs/xterm.js/releases/tag/3.12.1, beta for 3.13.0 coming soon so

All 18 comments

We've been seeing this same exception frequently in cocalc recently. As a sad workaround for now, we've been wrapping calls to resize in try/catch, to at least not crash the entire user's session. I also have no idea how to reproduce this. It's relatively recent, so probably caused by something introduced in 3.11 or 3.10.

We wanted to update to version 3.11.0 in cockpit but on testing I saw this exception as well. Also not able to reproduce this constantly, it happens randomly on resizing.

Sometimes I even see these (seem different as original issue, but most likely related):

Uncaught TypeError: Cannot read property 'get' of undefined
    at t._forEachCell (TextRenderLayer.js:51)
    at t._drawBackground (TextRenderLayer.js:101)
    at t.onGridChanged (TextRenderLayer.js:164)
    at Renderer.js:166
    at Array.forEach (<anonymous>)
    at t._renderRows (Renderer.js:166)
    at e._innerRefresh (RenderDebouncer.js:31)
    at RenderDebouncer.js:26
InputHandler.js:435 Uncaught TypeError: Cannot read property 'replaceCells' of undefined
    at t._eraseInBufferLine (InputHandler.js:435)
    at t.eraseInLine (InputHandler.js:489)
    at Array.<anonymous> (InputHandler.js:96)
    at n.parse (EscapeSequenceParser.js:402)
    at t.parse (InputHandler.js:191)
    at t._innerWrite (Terminal.js:893)
    at Terminal.js:875

I think this is a duplicate of https://github.com/xtermjs/xterm.js/issues/1926, I suspect there may still be an obscure crash still somewhere as I've had a few reports in https://github.com/Microsoft/vscode/issues/69603, but almost all cases appear to be fixed by that issue.

I've just tested with version 3.12.0 and can still reproduce the error. I'll let other people affected confirm, yet I don't think that's fixed.

If you can nail down a repro let me know as I can't repro https://github.com/Microsoft/vscode/issues/69603

If you can nail down a repro let me know as I can't repro Microsoft/vscode#69603

Yes, I'll try to have a minimal reproducer ASAP. Meanwhile, it'd be better to leave that open so other people affected may provider a reproducer too.

Hi @Tyriar,

After doing more tests, we found that this bug occurs when resizing cuts off tab symbol.

e.g. Seting cols to 8 and echo a\tb, then resizing cols to 7.

-- origin --

I found a way to reproduce this bug.

After cloning the repo and installing all dependencies, I run the demo page by yarn start.

bug

The following c code is the program I had executed in above gif.

#include <stdio.h>

int main() {
  int m, n;

  for (m = 1; m <= 9; ++m) {
    for (n = 1; n <= 9; ++n) {
      printf("%d * %d = %2d\t", m, n, m * n);
    }

    printf("\n=======================\n");
  }

  return 0;
}

Hi @Tyriar, I haven't dived into the source code too much. So it just my guess.

After some tracing, I think this bug may cause by reflowSmallerGetNewLineLengths that is called at:
https://github.com/xtermjs/xterm.js/blob/master/src/Buffer.ts#L304

Which define at:
https://github.com/xtermjs/xterm.js/blob/master/src/BufferReflow.ts#L174

The reason is that the value return by reflowSmallerGetNewLineLengths cause linesToAdd becoming -1.

We are hitting something like that in Theia as well: https://github.com/theia-ide/theia/pull/4680#issuecomment-476090542

I can reproduce it with running top -c and resizing the terminal widget.

Reproducible in latest VS Code as well:

  • split terminals several times
  • run dynamically updating command like top -c
  • resize this terminal
  • check dev tools
    Screen Shot 2019-03-25 at 11 04 46

I have some repro steps for this in vscode at least:

Repro steps:

  1. Use a twoline bash prompt that writes characters to the right edge of the terminal - https://gist.github.com/mkottman/1936195
  2. Open up integrated terminal and resize the width of the vscode window until the right edge of the window becomes narrower than where the time on the right hand side would have been.

Same can happen using split terminals

  1. Use two line prompt
  2. Open integrated terminal + split terminals
  3. Resize left terminal to take up most of the width
  4. Press enter to refresh the prompt to write chars near the right edge of the terminal
  5. Resize the left terminal back down, eventually it will trigger those same errors.

Source: https://github.com/Microsoft/vscode/issues/71572#issuecomment-478846614

@Tyriar Hi, just wanted to check whether you plan to look into it for 3.13?

I got a better repro:

  1. Run the demo
  2. ls
  3. Resize to 48 cols (optional)

    Screen Shot 2019-04-07 at 10 08 40 AM

  4. Resize to 47 cols

    Screen Shot 2019-04-07 at 10 08 48 AM

I think what's happening is that the trimmed line is being used on all parts of a wrapped line in reflowSmallerGetNewLineLengths when it should only be used on the last line. That's why it happens above, because of the way ls formats with \t which just advances the cursor.

I have a fix out in PR https://github.com/xtermjs/xterm.js/pull/2002. If anyone gets a chance, please see if you still have issues with that branch.

I confirm #2002 fixes the issue.

Thanks @Tyriar!

I released 3.12.1 that includes just this fix https://github.com/xtermjs/xterm.js/releases/tag/3.12.1, beta for 3.13.0 coming soon so

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnpoth picture johnpoth  路  3Comments

circuitry2 picture circuitry2  路  4Comments

chris-tse picture chris-tse  路  4Comments

goxr3plus picture goxr3plus  路  3Comments

Tyriar picture Tyriar  路  4Comments