question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UDP Ports leak on calling close on ApnsClient - 0.13.5

See original GitHub issue

I have a code where I keep fixed size cache of APNS clients. On eviction from the cache, apns clients are closed.

final Future<Void> closeFuture = entry.getKey().getApnsClient().close().addListener(new GenericFutureListener<Future<Void>>() {
	@Override
	public void operationComplete(Future<Void> future) throws Exception {
		if (future.isSuccess()) {
		    logger.info("Pushy APNS closed call success");
                } else {
		   logger.info("Pushy APNS closed call failed");
                }
        } 
});

I have confirmed the number of clients evicted from cache are equal to number of clients on which close got called successfully. But noticed the number of udp ports opened by the java process keeps increasing very highly. On enabling pushy and netty logging it seems these ports are opened due to RoundRobinDnsAddressResolverGroup and on close these ports are not closing. This open port count only keeps increasing due to large volume of evictions and close and over a period of some days app becomes unresponsive and needs a restart.

lsof -n -p <pid> | sed -n '1p;/UDP/p' | wc -l

I made local changes to Pushy in ApnsChannelFactory:: this.bootstrapTemplate.resolver to use DefaultAddressResolverGroup.INSTANCE and number of open udp ports became stable.

So https://github.com/relayrides/pushy/issues/632 doesn’t seem to be fixed

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jchamberscommented, Jun 4, 2019

netty/netty#9214 has been merged and should go out as part of Netty 4.1.37.

0reactions
eugeneseppelcommented, Aug 5, 2019

@jchambers I solicit for reopening this ticket again. After several weeks running in production I’ve figured out that experience a memory leak. There is a unit tests that shows this leak: ApnsClientTest.java, add this one:

    @Test
    public void test1() throws Exception {
        final SimpleApnsPushNotification pushNotification
                = new SimpleApnsPushNotification("apns:1111111111111111111111111111111111111111111111111111111111111111",
                "com.twilio.www", "{}");

        NioEventLoopGroup group = new NioEventLoopGroup(2);
        for(int i = 0; ; i++) {
            final ApnsClient client = new ApnsClientBuilder()
                    .setApnsServer("www.something.com") // to not flood apns
                    .setSigningKey(signingKey)
                    .setEventLoopGroup(group)
                    .build();
            Thread.sleep(10);
            client.sendNotification(pushNotification).await();
            client.close().await();

            if (i % 50 == 0) {
                Runtime.getRuntime().gc();
            }

            System.out.printf("y=%d\n", i);
        }
    }

Please run this test until 16000 iterations with current version of pushy and run $ while true; do ps axu|grep test1|grep -v grep|awk ‘{print $5,$6}’; sleep 2; done in terminal to check RSS is increasing After that you can eliminate usage/creation of RoundRobinAddressResolver in ApnsChannelFactory:

remove private final AddressResolverGroup addressResolverGroup; this.bootstrapTemplate.resolver(proxyHandlerFactory == null ? DefaultAddressResolverGroup.INSTANCE : NoopAddressResolverGroup.INSTANCE);

rerun this test and see that RSS is quite stable.

Moreover I have to add that currently in production our project consumes ~100 open UDP ports for resolver. (previously was ~1). It is not a serious issue for our usage pattern but quite strange why one need 100 ports to resolve just 2 APNS domain names

Read more comments on GitHub >

github_iconTop Results From Across the Web

UDP Ports leak on calling close on ApnsClient - 0.13.5 #675
I have a code where I keep fixed size cache of APNS clients. On eviction from the cache, apns clients are closed. final...
Read more >
TCP/IP port exhaustion troubleshooting - Windows Client
Most port leaks are caused by user-mode processes not correctly closing the ports when an error was encountered. At the user-mode level, ports...
Read more >
TCP and UDP ports used by Apple software products
Port TCP or. UDP RFC Service name 22 TCP 4253 ssh 25 TCP 5321 smtp 53 TCP/UDP 1034 domain
Read more >
Socket UDP client memory leak - Stack Overflow
The main problem is that you call close(clientSocket);. for all branches of the code except when you successfully read the data with ...
Read more >
Solved: Re: VoIP - Unknown UDP ports used - Cisco Community
And this goes to CUCM on ports 4000 and 4001. Those ports close as soon as I end the call. 0 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found