Skip to content
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

Response timeout for block transfer #388

Open
dakhnod opened this issue Dec 19, 2024 · 1 comment
Open

Response timeout for block transfer #388

dakhnod opened this issue Dec 19, 2024 · 1 comment

Comments

@dakhnod
Copy link

dakhnod commented Dec 19, 2024

Hey, thanks for your work!

I am running this code (taken from blockwise_put.js) to send a chunk of data:

const coap = require('../')

const bufferSize = 250000
const testBuffer = Buffer.alloc(bufferSize)
const containedData = 'This is a test buffer with a lot of nothing and a bit of something'
testBuffer.fill('X', 'utf-8')
testBuffer.write(containedData, 'utf-8')
testBuffer.write(containedData, testBuffer.length - containedData.length, containedData.length, 'utf-8')

const request = coap.request({
    hostname: 'fdd2:3ab9:44ef:78c5:3b48:3e87:df48:678e',
    port: 5683,
    pathname: '/test',
    method: 'PUT'
})
request.setOption('Block1', Buffer.from([6]))

request.on('response', (res) => {
    console.log('Client Received Response: ' + res.payload.toString('utf-8'))
    console.log('Client Received Response: ' + res.code)
    process.exit(0)
})
console.log('Sending large data from client...')
request.end(testBuffer)
console.log('Sent to server')

And this code (same source) to receive:

const coap = require('coap')

coap.createServer({ type: 'udp6' }, (req, res) => {
    setTimeout(() => {
        console.log('Server Received ' + req.payload.length + ' bytes')
        console.log('Sending back pleasantries')
        res.statusCode = '2.04'
        res.end('Congratulations!')
        console.log('Sent back')
    }, 500)
}).listen(() => {
    console.log('listening...')
})

Now, I am observing this behavior in wireshark:
image

And this error on the receiving side:

RetrySendError: No reply in 247 seconds.
at Timeout._onTimeout (/home/admin/coap/node_modules/coap/dist/lib/retry_send.js:56:25)
at listOnTimeout (node:internal/timers:581:17)
at process.processTimers (node:internal/timers:519:7)
Emitted 'error' event on OutMessage instance at:
RetrySend.emit (node:events:518:28)
at Timeout._onTimeout (/home/admin/coap/node_modules/coap/dist/lib/retry_send.js:58:22)
at listOnTimeout (node:internal/timers:581:17)
at process.processTimers (node:internal/timers:519:7) {
retransmitTimeout: 247
        inet6 fdd2:3ab9:44ef:78c5:0:ff:fe00:9c00  prefixlen 64  scopeid 0x0<global>                                                                                                       │}

While this is the stdout of the client:

Sending large data from client...
Sent to server
Client Received Response: Congratulations!
Client Received Response: 2.04

So, the reponse from the server seems to be parsed.

Do you have an idea why the packet is being retransmitted?

@dakhnod
Copy link
Author

dakhnod commented Dec 19, 2024

I think I found the culprit.
The callback

request.on('response', (res) => {
    console.log('Client Received Response: ' + res.payload.toString('utf-8'))
    console.log('Client Received Response: ' + res.code)
    process.exit(0)
})

gets called when the confirmable server response arrives.
Since the client then exits, the coap stack does not get the chance to confirm the server response.
Changing the callback to this fixes the issue:

request.on('response', (res) => {
    console.log('Client Received Response: ' + res.payload.toString('utf-8'))
    console.log('Client Received Response: ' + res.code)
    setTimeout(process.exit, 10)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant