{"action":"created","issue":{"url":"https://api.github.com/repos/mp911de/lettuce/issues/21","labels_url":"https://api.github.com/repos/mp911de/lettuce/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/mp911de/lettuce/issues/21/comments","events_url":"https://api.github.com/repos/mp911de/lettuce/issues/21/events","html_url":"https://github.com/mp911de/lettuce/issues/21","id":53968714,"number":21,"title":"Memory leak","user":{"login":"kichik","id":1156773,"avatar_url":"https://avatars.githubusercontent.com/u/1156773?v=3","gravatar_id":"","url":"https://api.github.com/users/kichik","html_url":"https://github.com/kichik","followers_url":"https://api.github.com/users/kichik/followers","following_url":"https://api.github.com/users/kichik/following{/other_user}","gists_url":"https://api.github.com/users/kichik/gists{/gist_id}","starred_url":"https://api.github.com/users/kichik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kichik/subscriptions","organizations_url":"https://api.github.com/users/kichik/orgs","repos_url":"https://api.github.com/users/kichik/repos","events_url":"https://api.github.com/users/kichik/events{/privacy}","received_events_url":"https://api.github.com/users/kichik/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mp911de/lettuce/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-10T19:34:14Z","updated_at":"2015-01-11T08:16:20Z","closed_at":null,"body":"The following code works for a while but stops receiving messages very quickly. When run without the debugger, I actually get the following error messages:\r\n\r\n```\r\n15/01/09 21:36:50 WARN channel.DefaultChannelPipeline: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.\r\njava.lang.OutOfMemoryError: Java heap space\r\n```\r\n\r\nTo expedite the process I limit JVM memory with `-Xmx32m`. However, I first discovered this issue while running a production server with 6GB heap size. It was under very low load and received a small message every 20 seconds. At some point I noticed messages were not being delivered anymore and the logs threw the same OOM errors. A heap dump showed `buffer` in `com.lambdaworks.redis.protocol.CommanHandler` was a holding a contiguous 1GB array. It was trying to extend the buffer, but had no more huge contiguous blocks in the heap.\r\n\r\nI am weirdly unable to reproduce the OOM in a debugger. However, when running in a debugger, I still do get the same issue with messages not being received after a while.\r\n\r\n```java\r\nimport java.util.Arrays;\r\nimport java.util.concurrent.ExecutionException;\r\nimport java.util.logging.Logger;\r\n\r\nimport com.lambdaworks.redis.RedisClient;\r\nimport com.lambdaworks.redis.RedisConnection;\r\nimport com.lambdaworks.redis.RedisURI;\r\nimport com.lambdaworks.redis.codec.Utf8StringCodec;\r\nimport com.lambdaworks.redis.pubsub.RedisPubSubConnectionImpl;\r\nimport com.lambdaworks.redis.pubsub.RedisPubSubListener;\r\n\r\n\r\npublic class LettuceMemoryLeak implements RedisPubSubListener<String, String>\r\n{\r\n\r\n    private static Logger LOGGER = Logger.getLogger( \"LettuceMemoryLeak\" );\r\n\r\n\r\n    public static void main( String[] args ) throws InterruptedException, ExecutionException\r\n    {\r\n        RedisURI uri = RedisURI.Builder.sentinel( \"localhost\", 26379, \"mymaster\" ).build();\r\n        RedisClient client = new RedisClient( uri );\r\n\r\n        RedisPubSubConnectionImpl<String, String> subscriber = client.connectPubSub( new Utf8StringCodec() );\r\n        subscriber.subscribe( \"test\" );\r\n        subscriber.addListener( new LettuceMemoryLeak() );\r\n\r\n        RedisConnection<String, String> publisher = client.connect( new Utf8StringCodec() );\r\n\r\n        char[] chars = new char[8096];\r\n        Arrays.fill( chars, 'a' );\r\n        String str = new String( chars );\r\n\r\n        while( true ) {\r\n            publisher.publish( \"test\", str );\r\n        }\r\n    }\r\n\r\n\r\n    @Override\r\n    public void message( String channel, String message )\r\n    {\r\n        LOGGER.info( channel );\r\n    }\r\n\r\n\r\n    @Override\r\n    public void message( String pattern, String channel, String message )\r\n    {\r\n    }\r\n\r\n\r\n    @Override\r\n    public void subscribed( String channel, long count )\r\n    {\r\n        LOGGER.info( \"subscribed to \" + channel + \" \" + count );\r\n    }\r\n\r\n\r\n    @Override\r\n    public void psubscribed( String pattern, long count )\r\n    {\r\n    }\r\n\r\n\r\n    @Override\r\n    public void unsubscribed( String channel, long count )\r\n    {\r\n    }\r\n\r\n\r\n    @Override\r\n    public void punsubscribed( String pattern, long count )\r\n    {\r\n    }\r\n\r\n}\r\n```\r\n\r\nI'll update this ticket once I have more information."},"comment":{"url":"https://api.github.com/repos/mp911de/lettuce/issues/comments/69487054","html_url":"https://github.com/mp911de/lettuce/issues/21#issuecomment-69487054","issue_url":"https://api.github.com/repos/mp911de/lettuce/issues/21","id":69487054,"user":{"login":"mp911de","id":1035015,"avatar_url":"https://avatars.githubusercontent.com/u/1035015?v=3","gravatar_id":"","url":"https://api.github.com/users/mp911de","html_url":"https://github.com/mp911de","followers_url":"https://api.github.com/users/mp911de/followers","following_url":"https://api.github.com/users/mp911de/following{/other_user}","gists_url":"https://api.github.com/users/mp911de/gists{/gist_id}","starred_url":"https://api.github.com/users/mp911de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mp911de/subscriptions","organizations_url":"https://api.github.com/users/mp911de/orgs","repos_url":"https://api.github.com/users/mp911de/repos","events_url":"https://api.github.com/users/mp911de/events{/privacy}","received_events_url":"https://api.github.com/users/mp911de/received_events","type":"User","site_admin":false},"created_at":"2015-01-11T08:16:20Z","updated_at":"2015-01-11T08:16:20Z","body":"Thanks for the memory leak fix. I'll make up my mind about exceptions on connections and the result of exceptions on the whole state."}}