WojciechZankowski / iextrading4j

IEX Cloud open source API wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DEEP Connection was leaked

90301 opened this issue · comments

Describe the bug
Using multiple DEEP websocket trade requests for different symbols, after a while I start exclusively etting this error:

WARNING: A connection to https://ws-api.iextrading.com/ was leaked. Did you forget to close a response body? To see where this was allocated, set the OkHttpClient logger level to FINE: Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);
Nov 27, 2018 2:58:50 PM okhttp3.internal.platform.Platform log

To Reproduce
Steps to reproduce the behavior:
Here's my implementation:

	public static void setupAsyncDeep(Collection<String> symbols)  {
		symbols.stream().forEach(x -> setupAsyncDeep(x));
	}
	
	public static void setupAsyncDeep(String symbol) {
		final SocketRequest<DeepAsyncResponse<DeepResult>> request = new DeepAsyncRequestBuilder()
		        .addChannel(DeepChannel.TRADES)
		        .withSymbol(symbol)
		        .build();

		iexTradingClient.subscribe(request, x -> processDeepTrade(symbol,x));
	}

	public static void processDeepTrade(String symbol, DeepAsyncResponse<DeepResult> x) {
		Trade t = (Trade) x.getData();
		//processTrade(symbol,t); //Application Specific Database Store
		
		System.out.println("Trade Logged: " + t);
	}

After 30 minutes to an hour The above warning error message repeats every time data arrives. No other console output occurs.

Expected behavior
The socket should continue to process data correctly as it comes in.

Screenshots
image

Additional context
At least for now, you can't specify multiple symbols in a single deep request (According to the IEX documentation). Hence the multiple requests.

Hey,

I will take a look at it. Thanks!

Unfortunately it seems that there is nothing what I can do about this issue at the moment.

IEX Trading provides their near real-time data using socket.io websocket technology. To receive this data I use official socket.io library. Issue that you reported comes from OKHttp3 library that is used by Socket.IO library. So this socket.io library is somehow not using okhttp3 library properly and it starts to leak connections after some time...

In IEX API v2 they promised to provide new way to receive event data: https://iexcloud.io/