Aha, my problem was that I was trying to read from stdin before returning
from my Command.start() implementation. If I call new-connection-fn on a
separate thread, it works.

Would it be reasonable to either 1) throw an exception if anyone tries to
read/write a stream before returning from start() or 2) allow reading from
stdin rather than blocking forever? The current behavior is confusing.

This is the fix:
https://github.com/matvore/hesokuri/commit/5cb13e0a81d7ece6aebdf5c635d150bac1719bf1


2014-04-20 7:05 GMT-07:00 Matthew DeVore <[email protected]>:

> That doesn't appear to be the problem. The spit function creates a Writer
> around the input stream and then closes it, which should get the underlying
> InputStream closed and flushed.
>
> Just to make sure, I tried this in place of spit:
>     (.write client-in (int \newline))
>     (.flush client-in)
> And added a logging call inside the loop in read-line-stream to see if any
> character made it through, but the deadlock still happens at the same spot,
> and not even one character makes it through.
>
>
> 2014-04-20 0:43 GMT-07:00 Guillaume Nodet <[email protected]>:
>
> The getInvertedIn() output stream is buffered.  If you want to
>> actually send a small amount of data, you need to call flush() after
>> writing to the stream.
>>
>> Happy Easter,
>> Guillaume Nodet
>>
>>
>> 2014-04-20 5:15 GMT+02:00 Matthew DeVore <[email protected]>:
>>
>> > Hi,
>> >
>> > I'm trying to integrate Apache SSHD with my app and am running into a
>> > strange issue. I can establish a connection and open a channel on a
>> > subsystem, and then get the InputStreams and OutputStreams that
>> correspond
>> > to it. Data transferred over stderr and stdout seem to get transferred,
>> but
>> > anything written to stdin by the client is not getting to the server.
>> The
>> > client and server are both on localhost and using the SSHD library.
>> >
>> > I've written two unit tests to demonstrate this - one that passes
>> > (connect-stdout-stderr) and one that deadlocks (connect-stdin). The
>> code is
>> > in Clojure. I'd be very grateful if someone could point me in the right
>> > direction to fix the failing test.
>> >
>> > Thank you,
>> > Matt
>> >
>> > *Application code*:
>> >
>> >
>> https://github.com/matvore/hesokuri/blob/4d591abe22a3c24e8756b1316ef763be86b55225/src/hesokuri/ssh.clj
>> > *Tests*:
>> >
>> >
>> https://github.com/matvore/hesokuri/blob/4d591abe22a3c24e8756b1316ef763be86b55225/test/hesokuri/test_hesokuri/ssh.clj
>> >
>> > *Test log output:*
>> > 19:41:38:matvore-macbookpro2:~/hesokuri$ lein test :only
>> > hesokuri.test-hesokuri.ssh/connect-stdin
>> >
>> > lein test hesokuri.test-hesokuri.ssh
>> > Apr 19, 2014 7:51:41 PM
>> > org.apache.sshd.common.util.SecurityUtils$BouncyCastleRegistration run
>> > 資訊: Trying to register BouncyCastle as a JCE provider
>> > Apr 19, 2014 7:51:42 PM
>> > org.apache.sshd.common.util.SecurityUtils$BouncyCastleRegistration run
>> > 資訊: Registration succeeded
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.client.session.ClientSessionImpl
>> > <init>
>> > 資訊: Client session created
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.server.session.ServerSession
>> <init>
>> > 資訊: Server session created from /127.0.0.1:63408
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.client.session.ClientSessionImpl
>> > readIdentification
>> > 資訊: Server version string: SSH-2.0-SSHD-CORE-0.10.1
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.common.session.AbstractSession
>> > negotiate
>> > 資訊: Kex: server->client aes128-ctr hmac-sha2-256 none
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.common.session.AbstractSession
>> > negotiate
>> > 資訊: Kex: client->server aes128-ctr hmac-sha2-256 none
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.common.session.AbstractSession
>> > negotiate
>> > 資訊: Kex: server->client aes128-ctr hmac-sha2-256 none
>> > Apr 19, 2014 7:51:42 PM org.apache.sshd.common.session.AbstractSession
>> > negotiate
>> > 資訊: Kex: client->server aes128-ctr hmac-sha2-256 none
>> > Apr 19, 2014 7:51:43 PM
>> > org.apache.sshd.server.session.ServerUserAuthService process
>> > 資訊: Session hesokuri_user@/127.0.0.1:63408 authenticated
>> > Apr 19, 2014 7:51:43 PM clojure.tools.logging$eval532$fn__538 invoke
>> > 資訊: wait on promise...
>> > Apr 19, 2014 7:51:43 PM clojure.tools.logging$eval532$fn__538 invoke
>> > 資訊: read line...
>> > *(deadlock here)*
>> >
>>
>
>

Reply via email to