You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Clinton Nielsen (JIRA)" <ji...@apache.org> on 2012/10/04 22:53:47 UTC

[jira] [Created] (HTTPCLIENT-1245) org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized

Clinton Nielsen created HTTPCLIENT-1245:
-------------------------------------------

             Summary: org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized
                 Key: HTTPCLIENT-1245
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1245
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: Cache
    Affects Versions: 4.2.1
            Reporter: Clinton Nielsen


Function:

    public String hash(String key) {
        MessageDigest md = getDigest();
        md.update(key.getBytes());
        return Hex.encodeHexString(md.digest());
    }


Should be rewritten to synchronize access to the MessageDigest object:

	public String hash(String key) {
        MessageDigest md = getDigest();
        byte[] digest = null;
        synchronized(md) {
        	md.update(key.getBytes());
        	digest = md.digest();
        }
        return Hex.encodeHexString(digest);
    }



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1245) org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized

Posted by "Clinton Nielsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469715#comment-13469715 ] 

Clinton Nielsen commented on HTTPCLIENT-1245:
---------------------------------------------

We're seeing issues in our application where it definitely seems that the message digest is incorrect under heavily multi-threaded load.
I'm running more tests now. I may have opened this defect prematurely.
                
> org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1245
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1245
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Clinton Nielsen
>
> Function:
>     public String hash(String key) {
>         MessageDigest md = getDigest();
>         md.update(key.getBytes());
>         return Hex.encodeHexString(md.digest());
>     }
> Should be rewritten to synchronize access to the MessageDigest object:
> 	public String hash(String key) {
>         MessageDigest md = getDigest();
>         byte[] digest = null;
>         synchronized(md) {
>         	md.update(key.getBytes());
>         	digest = md.digest();
>         }
>         return Hex.encodeHexString(digest);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1245) org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized

Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469704#comment-13469704 ] 

Jon Moore commented on HTTPCLIENT-1245:
---------------------------------------

If you look at the implementation of getDigest, it returns a fresh MessageDigest instance every time, so the MessageDigest isn't shared across invocations. Can you explain why it needs to be synchronized in this case?

                
> org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1245
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1245
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Clinton Nielsen
>
> Function:
>     public String hash(String key) {
>         MessageDigest md = getDigest();
>         md.update(key.getBytes());
>         return Hex.encodeHexString(md.digest());
>     }
> Should be rewritten to synchronize access to the MessageDigest object:
> 	public String hash(String key) {
>         MessageDigest md = getDigest();
>         byte[] digest = null;
>         synchronized(md) {
>         	md.update(key.getBytes());
>         	digest = md.digest();
>         }
>         return Hex.encodeHexString(digest);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1245) org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized

Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469711#comment-13469711 ] 

Jon Moore commented on HTTPCLIENT-1245:
---------------------------------------

Just to be clear, I'm open to the fact that it might be necessary, I just want to understand why. :)

                
> org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1245
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1245
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Clinton Nielsen
>
> Function:
>     public String hash(String key) {
>         MessageDigest md = getDigest();
>         md.update(key.getBytes());
>         return Hex.encodeHexString(md.digest());
>     }
> Should be rewritten to synchronize access to the MessageDigest object:
> 	public String hash(String key) {
>         MessageDigest md = getDigest();
>         byte[] digest = null;
>         synchronized(md) {
>         	md.update(key.getBytes());
>         	digest = md.digest();
>         }
>         return Hex.encodeHexString(digest);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Closed] (HTTPCLIENT-1245) org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized

Posted by "Clinton Nielsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Clinton Nielsen closed HTTPCLIENT-1245.
---------------------------------------

    Resolution: Not A Problem

Yeah, this is definitely going to require more digging around on my part.
I believe that the synchronization is not necessary.

Sorry for the trouble.
                
> org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1245
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1245
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Clinton Nielsen
>
> Function:
>     public String hash(String key) {
>         MessageDigest md = getDigest();
>         md.update(key.getBytes());
>         return Hex.encodeHexString(md.digest());
>     }
> Should be rewritten to synchronize access to the MessageDigest object:
> 	public String hash(String key) {
>         MessageDigest md = getDigest();
>         byte[] digest = null;
>         synchronized(md) {
>         	md.update(key.getBytes());
>         	digest = md.digest();
>         }
>         return Hex.encodeHexString(digest);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] [Commented] (HTTPCLIENT-1245) org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized

Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470003#comment-13470003 ] 

Jon Moore commented on HTTPCLIENT-1245:
---------------------------------------

No problem. Glad you're using the library and willing to report things you find!

                
> org.apache.http.impl.client.cache.memcached.SHA256KeyHashingScheme use of MessageDigest should be synchronized
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1245
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1245
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Clinton Nielsen
>
> Function:
>     public String hash(String key) {
>         MessageDigest md = getDigest();
>         md.update(key.getBytes());
>         return Hex.encodeHexString(md.digest());
>     }
> Should be rewritten to synchronize access to the MessageDigest object:
> 	public String hash(String key) {
>         MessageDigest md = getDigest();
>         byte[] digest = null;
>         synchronized(md) {
>         	md.update(key.getBytes());
>         	digest = md.digest();
>         }
>         return Hex.encodeHexString(digest);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org