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

Timeout callback #77

Closed
glenarama opened this issue Feb 8, 2024 · 11 comments
Closed

Timeout callback #77

glenarama opened this issue Feb 8, 2024 · 11 comments
Assignees
Labels
question Further information is requested

Comments

@glenarama
Copy link

Utilising a TLS connection i don't appear to get any timeout callback/error.
Looking at the code, I don't on timeout and wondered if/how it was handled?

Thanks!

@Bugs5382 Bugs5382 self-assigned this Feb 11, 2024
@Bugs5382
Copy link
Owner

@glenarama - Let me check.... I am pretty sure I had to take out the timeout code or option since tls.connect does this by default. I had to remove and move around how things work. The only difference between the TLS and non-TLS connect is just it having to use certificates to connect and the timeout on non-TLS does work.

@glenarama
Copy link
Author

Im ok with the default timeout actually - but I can't seem to capture the timeout event. It isn't thrown as an error.

@Bugs5382
Copy link
Owner

The timeout event has been elusive to me as well... I think I had to get rid of it cause the timeout happens and then the error event kicked in. Originally I was overriding "error". emit on the socket, causing some issues that you reported before so I had to re-write it to no folow that format....

Use the:

 this.emit('client.error', connectionError)

Event. It should capture a timeout.

@glenarama
Copy link
Author

Do we need something like the below on the connection client to throw it?

client.on('timeout', function timeout() {
    callback(new Error('Request timed out'));
  });

@Bugs5382
Copy link
Owner

I had that at one point... didn't quite seem to do anything cause by the time i try to do a "retry", timeout event is not thrown. I think that might be the issue cause I am forcing the socket to skip that in a way. I can see if putting it back in works and through it against the server (which I created a docker instance to do testing and the corepoint server) to see if it throws, but since I built int he auto-reconnect, it might not fire.

@Bugs5382
Copy link
Owner

Yeah, so..

Event: 'timeout'#
Added in: v0.1.90
Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.

See also: socket.setTimeout().

This is from Node Docs. Timeout is idle, not connection. I had a connectionTimer in there but it was being messed up. I can see if I can add it back end to send client.timeout event vs. 'timeout'

@Bugs5382
Copy link
Owner

So I could do this:

image

But it just be continuous 'timeout' emits until it connects. I rather have a limit as well of the number of attempts before moving along. Pairing that with the code underneath, I would skip this block if there was already a successful connection prior until the max retires already complicating the situation. So unlimited timeouts which then the app would have to manage and retry at that point or it's own internal count of when it fals completely.

@glenarama
Copy link
Author

Yes ideal workflow for me would be:

Connect -> [Timeout OR Error] -> Retry until count -> Emit Timeout or Error message -> Exit

@Bugs5382
Copy link
Owner

Ok. I think the min. timeout will have to be 10 seconds cause in 99.6% of the time connection will happen right away. This way as well I can create a proper unit test without having to override the defaults.

@Bugs5382
Copy link
Owner

@glenarama Ok.. check this out updated unit test:

image

From adding this:

image

That will fire 'client.timeout' in this case in about 1 second. The console would be gone, but ECONNREFUSED which was already being captures in this unit test from client.error works. client.timeout just says, yep, we tried again and if you wanted the error, check on client.error event for what really happened.

@Bugs5382 Bugs5382 added the question Further information is requested label Feb 16, 2024
@Bugs5382
Copy link
Owner

Fixed in #83

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

When branches are created from issues, their pull requests are automatically linked.

2 participants