node-x11 icon indicating copy to clipboard operation
node-x11 copied to clipboard

Error: write after end

Open johannesjo opened this issue 7 years ago • 9 comments

I'm trying to get a list of all open windows. Seems to me like an actual issue with node-x11 and not x11 itself:

This is the stacktrace:

Error: write after end
    at writeAfterEnd (_stream_writable.js:193:12)
    at Socket.Writable.write (_stream_writable.js:244:5)
    at Socket.write (net.js:658:40)
    at UnpackStream.<anonymous> (/home/user/app/node_modules/x11/lib/xcore.js:82:16)
    at emitOne (events.js:96:13)
    at UnpackStream.emit (events.js:188:7)
    at UnpackStream.flush (/home/user/app/node_modules/x11/lib/unpackstream.js:311:15)
    at XClient.req_proxy [as GetProperty] (/home/user/app/node_modules/x11/lib/xcore.js:231:37)
    at X.InternAtom (/home/user/app/x11-wrapper.js:99:7)
    at ReadFixedRequest.callback (/home/user/app/node_modules/x11/lib/xcore.js:545:21)

This is the code I'm running:

X.InternAtom(false, '_NET_CLIENT_LIST', (err, atomId) => {
    console.log(atomId);
    X.GetProperty(0, root, atomId, X.atoms.CARDINAL, 0, 100000, (err, prop) => {
      console.log('HERE', prop.data, prop.data.toString());
    });
  });

_NET_CLIENT_LIST_STACKING and _WIN_CLIENT_LIST result in the same error. So does leaving out the additional parameters.

johannesjo avatar Apr 24 '17 16:04 johannesjo

What's your DISPLAY look like? Is it local connection? 'writeAfterEnd' means initial connection was successful but later server unexpectedly closed connection. Might be authentication issue ( afaik this library only supports MIT-MAGIC-COOKIE-1 method - see https://en.wikipedia.org/wiki/X_Window_authorization )

sidorares avatar Apr 25 '17 11:04 sidorares

Thanks for getting back to me. What do you mean by display? The environment variable? That's :1. And yes it is a local connection.

johannesjo avatar Apr 25 '17 11:04 johannesjo

Error: write after end at writeAfterEnd (_stream_writable.js:193:12) at WriteStream.Writable.write (_stream_writable.js:240:5) at log (/usr/local/lib/node_modules/genieacs/lib/logger.js:260:15) at Object.error (/usr/local/lib/node_modules/genieacs/lib/logger.js:279:3) at process. (/usr/local/lib/node_modules/genieacs/lib/server.js:77:10) at emitOne (events.js:96:13) at process.emit (events.js:188:7) at process._fatalException (bootstrap_node.js:296:26) issue persist , need a help

jmccandles146 avatar Jun 27 '17 13:06 jmccandles146

@jmccandles146 what's your OS?

sidorares avatar Jun 27 '17 13:06 sidorares

centOS-7

jmccandles146 avatar Jun 27 '17 13:06 jmccandles146

@jmccandles146 it looks to me that error is completely unrelated to node-x11. genieacs loggers tries to write to a socket after it was closed ( Stream is process stderr - https://github.com/zaidka/genieacs/blob/ec1360217b68e2947c47f8b3a17ea97af7a773f5/lib/logger.js#L38 ) something closes stderr fd

sidorares avatar Jun 27 '17 14:06 sidorares

is it the connection error with MongoDB

jmccandles146 avatar Jun 27 '17 14:06 jmccandles146

I get the same when I try to get all the properties of a window, like in this smoke test:

    X.ListProperties(id, function(err, props) {
        props.forEach(function(p) {
            X.GetProperty(0, id, p, 0, 0, 10000000, function(err, propValue) {
                X.GetAtomName(propValue.type, function(err, typeName) {
                    X.GetAtomName(p, function(err, propName) {
                        decodeProperty(typeName, propValue.data, function(decodedData) {
                            console.log(propName + '(' + typeName + ') = ' + decodedData);
                        });
                    });
                });
            });
        })   
    });
    X.on('event', console.log);
    X.on('error', console.error);
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:243:12)
    at Socket.Writable.write (_stream_writable.js:291:5)
    at UnpackStream.<anonymous> (/home/user/myproject/node_modules/x11/lib/xcore.js:82:16)
    at UnpackStream.emit (events.js:189:13)
    at UnpackStream.flush (/home/user/myproject/node_modules/x11/lib/unpackstream.js:311:15)
    at XClient.req_proxy [as GetProperty] (/home/user/myproject/node_modules/x11/lib/xcore.js:231:37)
    at /home/user/myproject/lib/x11Wrapper.js:222:9
    at Array.forEach (<anonymous>)
    at /home/user/myproject/lib/x11Wrapper.js:221:11
    at ReadFixedRequest.callback (/home/user/myproject/node_modules/x11/lib/xcore.js:545:21)

johannesjo avatar Sep 27 '19 11:09 johannesjo

My bad. The issue was recreating and terminating the x11 server for every command I executed...

johannesjo avatar Sep 27 '19 12:09 johannesjo