Open caocong1 opened 3 years ago
I've got the same issue, but reading a file.
var smb2Client = new SMB2({
share: '\\\\my-server\\public-share'
, domain: ''
, username: ''
, password: ''
});
// existance
const appl = await new Promise((res, rej) => {
smb2Client.exists('my-file', function (err, exists) {
if (err) throw err;
debug(exists);
res(exists);
});
});
if (!appl) {
console.error("my-file doesn't exist");
process.exit(1);
}
// appl is true also when error is thrown!
const applFile = await new Promise((res, rej) => {
smb2Client.readFile('my-file', { encoding: null }, function (err, data) {
if (err) throw err; <-- error here
debug(data.length);
debug(data);
res(data);
});
});
fs.writeFileSync(path.join(tempFolder, "my-file"), applFile);
Error: STATUS_PENDING (0x00000103) : The operation that was requested is pending completion.
at SMB2Forge.request (/home/dl.net_mlelli/dev/repos/image-accelerator/node_modules/@marsaud/smb2/lib/tools/smb2-forge.js:22:15)
at createPackets (/home/dl.net_mlelli/dev/repos/image-accelerator/node_modules/@marsaud/smb2/lib/api/readFile.js:79:11)
at checkDone (/home/dl.net_mlelli/dev/repos/image-accelerator/node_modules/@marsaud/smb2/lib/api/readFile.js:57:9)
at /home/dl.net_mlelli/dev/repos/image-accelerator/node_modules/@marsaud/smb2/lib/api/readFile.js:50:13
at Object.<anonymous> (/home/dl.net_mlelli/dev/repos/image-accelerator/node_modules/@marsaud/smb2/lib/tools/message.js:15:15)
at Socket.<anonymous> (/home/dl.net_mlelli/dev/repos/image-accelerator/node_modules/@marsaud/smb2/lib/tools/smb2-forge.js:71:31)
at Socket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at Socket.Readable.push (internal/streams/readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
messageName: 'read',
params: {
FileId: Buffer(16) [Uint8Array] [
64, 54, 190, 186, 0, 0,
0, 0, 99, 231, 127, 125,
0, 0, 0, 0
],
Length: 65536,
Offset: Buffer(8) [Uint8Array] [
0, 0, 150, 0,
0, 0, 0, 0
]
},
code: 'STATUS_PENDING'
}
I've resolved with a hack, I don't sure if this is the right way to do it but maybe could help to resolve the problem.
SMB2Forge.response = function (c) {
c.responses = {}
c.responsesCB = {}
c.responseBuffer = Buffer.allocUnsafe(0)
return function (response) {
// concat new response
c.responseBuffer = Buffer.concat([c.responseBuffer, response])
// extract complete messages
var extract = true
while (extract) {
extract = false
// has a message header
if (c.responseBuffer.length >= 4) {
// message is complete
var msgLength = (c.responseBuffer.readUInt8(1) << 16) + c.responseBuffer.readUInt16BE(2)
if (c.responseBuffer.length >= msgLength + 4) {
// set the flags
extract = true
// parse message
var r = c.responseBuffer.slice(4, msgLength + 4)
var message = new SMB2Message()
message.parseBuffer(r)
// debug
if (c.debug) {
console.log('--response') // eslint-disable-line no-console
console.log(r.toString('hex')) // eslint-disable-line no-console
}
// get the message id
var mId = message.getHeaders().MessageId.toString('hex')
// check if the message can be dispatched
// or store it
if (c.responsesCB[mId]) {
const Status = message.getHeaders().Status.toString('hex')
// Check the error, in case of STATUS_PENDING skip the parsing function
if (Status != '03010000') {
c.responsesCB[mId](message)
delete c.responsesCB[mId]
}
} else {
c.responses[mId] = message
}
// remove from response buffer
c.responseBuffer = c.responseBuffer.slice(msgLength + 4)
}
}
}
}
}
I agree, it appears that this node has issues being executed multiple times, while it's still in use. Therefore I added a delay node before it and change the delay node to limit the rate of messages of 1 per second. Not thrilled that I have to cause a delay, but it works for now.
I found out the reason is async request. But I don't know how to do.