tags:

views:

114

answers:

0

NOTE: I'll use the ssh_sftp channel as an example here, but I've noticed the same behaviour when using different channels.

After starting a channel:

{ok, ChannelPid} = ssh_sftp:start_channel(State#state.cm),

(where cm is my Connection Manager), I'm performing an operation through the channel. Say:

ssh_sftp:write_file(ChannelPid, FilePath, Content),

Then, I'm stopping the channel:

ssh_sftp:stop_channel(ChannelPid),

Since, as far as I know, the channel is implemented as a gen_server, I was expecting the requests to be sequentialized.

Well, after a bit of tracing, I've noticed that the channel is somehow stopped before the file write is completed and the result of the operation is sent through the channel. As a conclusion, the response is not sent through the channel, since the channel doesn't exist anymore.

If I don't stop the channel explicitely, everything works fine and the file write (or any other operation performed through the channel) is completed correctly. But I would prefer to avoid to leave open channels. On the other hand, I would prefer to avoid implementing my own receive handler to wait for the result before the channel can be stopped.

I'm probably missing something trivial here. Do you have any idea why this is happening and/or I could fix it?

I repeat, the ssh_sftp is just an example. I'm using my own channels, implemented using the existing channels in the Erlang SSH application as a template.