-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream read/write duplication #160
Comments
I faced the same issue. |
Is there any solution to this problem? |
Can you please try providing a PR to fix this issue? I cannot reproduce it on my end. |
In the Stream class in index.js, I commented out this.push(data), and it fixed the problem. I used npm patch-package as a temporary solution. I'd have to dig a little bit to see what the PR should look like, but this might help shed some light. this.source.write(data, encoding, () => { |
I followed the method you provided, and it fixed the problem. 👍 |
I'm not aware of any side effects, it seems to work as expected. Although, I haven't gotten around to looking at this further, so I can't guarantee that there are none. |
Got it. Thank you. |
@mkozjak |
What line and file is this?
… On 11.03.2021., at 04:47, shinhwa520 ***@***.***> wrote:
@mkozjak
May I ask the reason why does it needs to do "push" on "source.write" listener?
Does it have a special purpose?
Will it cause any side effects if I delete this line?
Thank you.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Sorry for not clarifying in my earlier comment. The code is at line 445 in "lib/index.js" file. class Stream extends Duplex {
constructor(source, options) {
super(options)
this.source = source
this.source.on('data', (data) => this.push(data))
}
_write(data, encoding, cb) {
if (!this.source.writable) {
cb(new Error('socket not writable'))
}
this.source.write(data, encoding, () => {
this.push(data) <<<<<<<<<<< this line
cb()
})
}
_read() {}
} Thank you. |
If you’re not using .shell function it should be safe. Run the tests. |
I'm using the .shell function, but I tested the code that deletes the line and it seems to work fine. My source code is as below: const Telnet = require('telnet-client');
...
let conn = new Telnet();
...
conn.shell((err, stream) => {
socket.on('disconnecting', function socketOnDisconnecting(reason) {
...
})
socket.on('disconnect', function socketOnDisconnect(reason) {
...
})
socket.on('error', function socketOnError(err) {
...
})
stream.on('data', function streamOnData(data) {
if (data.indexOf('Connection closed') !== -1 || data.indexOf('[ERROR]') !== -1) {
socket.disconnect();
} else {
socket.emit('dataFromServer', data.toString());
}
})
stream.on('close', function streamOnClose(code, signal) {
socket.disconnect();
})
socket.on('dataFromWeb', function socketOnData(data) {
stream.write(data);
})
}) |
@shinhwa520 based on past comments, I feel it's okay to remove that line. Please provide a PR removing the arrow function altogether and instead of it, just provide |
Okay, I have already created a PR for this. |
Tackling this with #187. @shinhwa520 Should we take care of the test
|
Signed-off-by: Mario Kozjak <kozjakm1@gmail.com>
@shinhwa520 Is this looking good? |
Hello, I'm trying to open an interactive shell session and I'm running into an issue where I am seeing my input duplicated when it is piped back to
process.stdout
.The code:
And the output I'm seeing:
You can see that the text I typed in is duplicated (e.g. typed "foo", displayed as "ffoooo"), but the input was properly written to the stream ("-sh foo: not found").
Is there something I'm doing wrong or otherwise should be doing differently?
The text was updated successfully, but these errors were encountered: