Skip to content

Commit

Permalink
Handle de-serialization errors as bad cache data and just return null…
Browse files Browse the repository at this point in the history
…, but don't force close the client socket connection
  • Loading branch information
Gary Helmling committed Dec 1, 2009
1 parent de712fd commit 6423ceb
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/com/meetup/memcached/MemcachedClient.java
Expand Up @@ -1376,14 +1376,26 @@ public Object get( String key, Integer hashCode, boolean asString ) {
if ( log.isInfoEnabled() )
log.info( "++++ deserializing " + o.getClass() );
}
catch ( InvalidClassException e ) {
/* Errors de-serializing are to be expected in the case of a
* long running server that spans client restarts with updated
* classes.
*/
// if we have an errorHandler, use its hook
if ( errorHandler != null )
errorHandler.handleErrorOnGet( this, e, key );

o = null;
log.error( "++++ InvalidClassException thrown while trying to deserialize for key: " + key + " -- " + e.getMessage() );
}
catch ( ClassNotFoundException e ) {

// if we have an errorHandler, use its hook
if ( errorHandler != null )
errorHandler.handleErrorOnGet( this, e, key );

o = null;
log.error( "++++ ClassNotFoundException thrown while trying to deserialize for key: " + key + " -- " + e.getMessage() );
throw new NestedIOException( "+++ failed while trying to deserialize for key: " + key, e );
}
}
}
Expand Down Expand Up @@ -1717,19 +1729,32 @@ private void loadMulti( LineInputStream input, Map<String,Object> hm, boolean as
if ( log.isInfoEnabled() )
log.info( "++++ deserializing " + o.getClass() );
}
catch ( InvalidClassException e ) {
/* Errors de-serializing are to be expected in the case of a
* long running server that spans client restarts with updated
* classes.
*/
// if we have an errorHandler, use its hook
if ( errorHandler != null )
errorHandler.handleErrorOnGet( this, e, key );

o = null;
log.error( "++++ InvalidClassException thrown while trying to deserialize for key: " + key + " -- " + e.getMessage() );
}
catch ( ClassNotFoundException e ) {

// if we have an errorHandler, use its hook
if ( errorHandler != null )
errorHandler.handleErrorOnGet( this, e, key );

o = null;
log.error( "++++ ClassNotFoundException thrown while trying to deserialize for key: " + key + " -- " + e.getMessage() );
throw new NestedIOException( "+++ failed while trying to deserialize for key: " + key, e );
}
}

// store the object into the cache
hm.put( key, o );
if ( o != null )
hm.put( key, o );
}
else if ( END.equals( line ) ) {
if ( log.isDebugEnabled() )
Expand Down

0 comments on commit 6423ceb

Please sign in to comment.