directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maciej Miklas (JIRA)" <>
Subject [jira] [Created] (DIRKRB-620) KerberosChannel does not read whole response
Date Thu, 23 Feb 2017 11:57:44 GMT
Maciej Miklas created DIRKRB-620:

             Summary: KerberosChannel does not read whole response
                 Key: DIRKRB-620
             Project: Directory Kerberos
          Issue Type: Bug
          Components: changepw
            Reporter: Maciej Miklas

We have in production some customers who cannot change their password. In log we observe following
20.02.2017 10:59:11,987 DEBUG [http-bio-]
- <<<==========================================
20.02.2017 10:59:11,987 ERROR [http-bio-]
- Authentication failed : timeout occured
20.02.2017 10:59:11,987 WARN [http-bio-]
- failed to change the password TimeOut occured

Real reason for this error is incorrect socket implementation:
            byte[] tmp = new byte[ 1024 * 8 ];
            while ( in.available() > 0 )
                int read = tmp );
                repData.put( tmp, 0, read );

You should not relay on _available()_ - it returns only assumption. In our case for some users
it returns 0 before whole message has been consumed.

In order to fix it, you should first read header of the message in order to figure out its
size. Now use until you consume expected amount of bytes. Eventually you will
run into timeout, which is fine and happens if server does not keep its promise from header
and cuts the message.

I've changed code into this:
	    byte[] tmp = new byte[1024 * 8];
	    int read;
	    try {
		while ((read = > 0) {
		    repData.put(tmp, 0, read);
	    catch (SocketTimeoutException e) {
		// OK

and customers now can change their password. Obviously this implementation is *incorrect*,
because it runs into timeout with every call. Bu it proves that using _available()_ does not

This message was sent by Atlassian JIRA

View raw message