[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Switching between blocking and non-blocking mode


Ah I see, thanks. Unfortunately in my case it's quite possible that there
will be new/outstanding requests coming in 😅 For now I guess the safest
option would be to have another session open in blocking mode just for SFTP
things.

Do you have an idea of how difficult it would be to extend the SFTP API to
work in non-blocking mode as well?


On Mon, Mar 24, 2025, 12:33 PM Jakub Jelen <jjelen@xxxxxxxxxx> wrote:

> Hi James!
> I think that given that we have an API for that, it should be possible
> to do so. But I think the special care needs to be taken to make sure
> that when you switch to blocking mode, there is no outstanding request
> that would need to be processed in the calls you are processing as it
> might lead to inconsistent internal state.
>
> Reading through the ssh_channel_open() code, on the first sight it
> looks like this state should be able to handle the switch from
> non-blocking to blocking after the first return of SSH_AGAIN (assuming
> your code will make sure any outstanding requests will be repeated
> after the switch). I believe the other states are constructed in
> similar way so they should work in similar way, but I did not check.
>
> If you are getting the error in some reproducible (or at least
> semi-reproducible way), looking at a debug log what operations were
> happening before the error and how it actually fails would help.
> Ideally in the separate gitlab issue so it wont get lost on the
> mailing list.
>
> Thanks,
> Jakub
>
> On Sat, Mar 22, 2025 at 4:50 PM James Wrigley <james@xxxxxxxxxxxxxx>
> wrote:
> >
> > Hi there,
> > I nominally use LibSSH in non-blocking mode, however in some cases I
> want to perform SFTP operations. Because the SFTP API does not support
> non-blocking mode right now my approach is to switch the session to
> blocking mode, do the SFTP operation, and then switch back to non-blocking
> mode. In my application I've noticed that this can sometimes lead to
> sftp_new() just failing for some reason. I haven't started debugging this
> properly, but my initial question is basically, is it safe to switch a
> session from blocking to non-blocking mode and back like this? Or is a
> session meant to be in a single mode for its entire lifetime?
> >
> > For context I'm using LibSSH in Julia, hence the session usually needs
> to be in non-blocking mode to play nicely with Julia's event loop.
> >
> > Thanks,
> > James
>
>
>

Follow-Ups:
Re: Switching between blocking and non-blocking modeJakub Jelen <jjelen@xxxxxxxxxx>
References:
Switching between blocking and non-blocking modeJames Wrigley <james@xxxxxxxxxxxxxx>
Re: Switching between blocking and non-blocking modeJakub Jelen <jjelen@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org