Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

CodecException: invalid WebSocket Extension handshake for "permessage-deflate; client_no_context_takeover" #81

Closed
jburgess opened this issue Jan 20, 2018 · 3 comments

Comments

@jburgess
Copy link

Hi, I am attempting to use the 4.3.2-SNAPSHOT of the GDAX Streaming library. Upon connection to the websocket, I receive the error:

09:57:09.137 [main] INFO  info.bitrich.xchangestream.gdax.GDAXStreamingService - Registering GDAXWebSocketClientHandler
io.netty.handler.codec.CodecException: invalid WebSocket Extension handshake for "permessage-deflate; client_no_context_takeover"
	at io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler.channelRead(WebSocketClientExtensionHandler.java:111)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1267)
	at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1078)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	at java.lang.Thread.run(Unknown Source)

Below are my dependencies:

		<dependency>
			<groupId>info.bitrich.xchange-stream</groupId>
			<artifactId>xchange-stream-core</artifactId>
			<version>4.3.2-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>info.bitrich.xchange-stream</groupId>
			<artifactId>xchange-gdax</artifactId>
			<version>4.3.2-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.knowm.xchange</groupId>
			<artifactId>xchange-core</artifactId>
			<version>4.3.2-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.knowm.xchange</groupId>
			<artifactId>xchange-examples</artifactId>
			<version>4.3.2-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.knowm.xchange</groupId>
			<artifactId>xchange-gdax</artifactId>
			<version>4.3.2-SNAPSHOT</version>
		</dependency>
@dcarr45
Copy link

dcarr45 commented Jan 22, 2018

I don't know a ton about what's actually going on in the underlying connections, but I encountered this error too and was able to get around it. GDAX apparently has very specific connection requirements, so it defines a WebSocketClientCompressionAllowClientNoContextHandler . In the connect() method in NettyStreamingService.java, the following lines add handlers to the channel:

WebSocketClientExtensionHandler clientExtensionHandler =
getWebSocketClientExtensionHandler();
List<ChannelHandler> handlers = new ArrayList<>(4);
handlers.add(new HttpClientCodec());
handlers.add(WebSocketClientCompressionHandler.INSTANCE);
handlers.add(new HttpObjectAggregator(8192));
handlers.add(handler);
if (clientExtensionHandler != null) handlers.add(clientExtensionHandler);
p.addLast(handlers.toArray(new ChannelHandler[handlers.size()]));

I believe the GDAX clientExtensionHandler is the correct configuration, while adding WebSocketClientCompressionHandler.INSTANCE produces the error. I just commented out that line... don't think that's really the best solution, but it appears to work without breaking too much else. It shouldn't be too hard to refactor that code to only not add the default WebSocketClientCompressionHandler.INSTANCE if the request is to GDAX though. Again, don't know what I'm doing, probably not the best idea.

@scionaltera
Copy link
Contributor

I tried what @dcarr45 did and at first glance it seems to be working for Bitfinex and GDAX. Will keep an eye on it and see if it has any side effects, since I don't really know what I'm doing yet either. Just cracked open the code for the first time today. 😁

@nodarret
Copy link
Contributor

Bitfinex also is broken by this commit e5d55da

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants