Thread: [Netty] Memory (ByteBuf) leak fix

Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1 [Netty] Memory (ByteBuf) leak fix 
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    UPDATED: Final adjustments, thanks to everyone who have commented
    This had been done on BattleOS base, if you're using a different base, make it match to yours, wherever your packet is being handled at, must call this AFTER packet has completely being used.

    @IncomingPacketHandlerRegistration#dispatchToHandl er:

    Replace with:
    Code:
    listener.ifPresent(msg -> {
                try {
                     msg.handlePacket(player, packet);
                } finally {
                    ReferenceCountUtil.release(packet);
                }
    });

    For more explanation visit:
    Netty.docs: Reference counted objects


    Netty version tested on: Netty.4.1.9-Final

    Note:
    - This has been detected on ResourceLeakDetector=Paranoid
    - This might be also useful for those who use this netty release on their server and have this occurring
    - This might work on different netty versionshttps://www.rune-server.ee/runescape...ml#post5378127
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Hmm never knew about that.. Thanks for the heads up
    Reply With Quote  
     

  4. #3  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Gnakos View Post
    Hmm never knew about that.. Thanks for the heads up
    Me neither, until I've enabled PARANOID resource leak detection, however, I'm not entirely sure what's the cause, yet this fix did stop the leak.
    Reply With Quote  
     

  5. #4  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by Tyrant View Post
    Me neither, until I've enabled PARANOID resource leak detection, however, I'm not entirely sure what's the cause, yet this fix did stop the leak.
    Feels like it has something todo with data not being fully read from the incoming packet, basiclly only read 12bytes of whole 14bytes or something but not sure, just a theory
    Reply With Quote  
     

  6. #5  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Gnakos View Post
    Feels like it has something todo with data not being fully read from the incoming packet, basiclly only read 12bytes of whole 14bytes or something but not sure, just a theory
    Possibly, anyhow, since if thats the case, it also makes sense to use this feature since packet is obviously not being used anymore. Or else?
    Reply With Quote  
     

  7. #6  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by Tyrant View Post
    Possibly, anyhow, since if thats the case, it also makes sense to use this feature since packet is obviously not being used anymore. Or else?
    Yeah thats true, good comparision to do with a database connection too and specially the 'resultset' which most people does not close which later on can cause a memleak.
    But.. it could also be interesting to find out which packet is not being fully read if thats the case..
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Apr 2017
    Posts
    301
    Thanks given
    34
    Thanks received
    59
    Rep Power
    65
    Thanks for this, will look more into this myself. Keep us updated on anything else related to this stuff.
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Update:

    A small issue I've witnessed how the #release() call may not complete, hence, having something like this may sort of solute the issue:

    Code:
        @Override
        public void finalize() throws Throwable {
            while (!payload.release()) 
                super.finalize();
            
        }
    However I have not tested this way, so something you might want to test by your own. let me know how it goes though.
    Reply With Quote  
     

  11. #9  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by Tyrant View Post
    Update:

    A small issue I've witnessed how the #release() call may not complete, hence, having something like this may sort of solute the issue:

    Code:
        @Override
        public void finalize() throws Throwable {
            while (!payload.release()) 
                super.finalize();
            
        }
    However I have not tested this way, so something you might want to test by your own. let me know how it goes though.
    Hmm..

    Code:
     listener.ifPresent(msg -> {
    	try {
    		msg.handlePacket(player, packet);
    	} finally {
    		packet.release();
    	}
    });
    Could that maybe solve the issue about release() not getting completed/called?
    Last edited by Gnakos; 05-13-2017 at 03:24 PM. Reason: Didnt knew try finally worked only try catch finally
    Reply With Quote  
     

  12. #10  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Gnakos View Post
    Hmm..

    Code:
     listener.ifPresent(msg -> {
    	try {
    		msg.handlePacket(player, packet);
    	} catch (Exception) {
    	} finally {
    		packet.release();
    	}
    });
    Could that maybe solve the issue about release() not getting completed/called?
    Absolutely, however I have not wrapped it with try-finally, it does seem to solute that issue though.
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [Battle-OS] Player appearance updating fix
    By Tyrant in forum Snippets
    Replies: 7
    Last Post: 05-19-2017, 08:04 PM
  2. Replies: 15
    Last Post: 04-19-2014, 02:36 PM
  3. Memory leak, paying for fix!
    By Russ in forum Help
    Replies: 5
    Last Post: 03-07-2011, 07:26 PM
  4. [PI] Memory Leak... $45 For Fix! [PI]
    By `Eclipse™ in forum Help
    Replies: 2
    Last Post: 02-12-2011, 11:17 AM
  5. [Delta] memory leak 10$ FOR FIX
    By Neekage in forum Help
    Replies: 7
    Last Post: 09-08-2010, 01:21 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •