?
Solved

Websocket through haproxy reused connection causes "Not a valid frame" error.

Posted on 2016-10-16
4
Medium Priority
?
193 Views
Last Modified: 2016-10-17
Hello Experts.

    Websocket-client connects to websocket-server through haproxy.
    Sometimes transmission works, sometimes not.
    Websocket-client is based on python2.6/site-packages/websocket_client-0.7.0-py2.6.egg/websocket.py
    Websocket-server based on c++ library.
    Haproxy version is 1.5.x

    As you can see, websocket client reuses connection when python-script is reentered.
    Note, if not to reuse the connection, there are no errors.

    How get rid of this error?
    #must we put here something to "flush" the "mysterios" ws "buffer"? ( See this comment in script )

    Script, error-trace, haproxy.cfg and log are attached.

Thank you.
script-and-error.txt
haproxy-cfg-and-log.txt
0
Comment
Question by:Bitlab
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:sarabande
ID: 41846960
   Note, if not to reuse the connection, there are no errors.
if so, can you try to always close an existing connection properly and then use a new connection?

reusing a connection which might not be terminated properly or is still used by someone, always makes trouble and it is difficult to impossible to handle this.

Sara
0
 
LVL 2

Author Comment

by:Bitlab
ID: 41846993
Thanks.
"reusing a connection which might not be terminated properly or is still used by someone" -
this kills a speed which is a purpose of keeping connection alive.

and how can it be terminated non-properly?
and who else can use the connection? the socket open between client, haproxy, and a server: there is no middle man
0
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 41847055
how can it be terminated non-properly?
there are two sides, client and server, and their tcp subsystems which were running asynchronously:
if one side disconnects, the other side needs to be informed to close the connection as well. it wouldn't get knowledge of the termination automatically but only if it tries to read or write. note, i don't know what libraries you were using. some of them may solve the those issues properly for you. some will not. and if someone blocks the connection - say because not all data sent are read from other, it is impossible to reuse it. note, shutdown will not immediately terminate, since tcp always will try to have a graceful closing process.

who else can use the connection? the socket open between client, haproxy, and a server: there is no middle man
isn't the haproxy a load-balancer? if so, it manages multiple connections to multiple servers, right? i wonder that you are  allowed to 'reuse' a connection when using haproxy.

this kills a speed which is a purpose of keeping connection alive.
did you measure it? you easily can keep connections alive if your clients were using an own service for handling the connection. if one connection is used always by the same client, you could use an own thread which keeps the connection alive. if you do so, you never need to reuse but only use the one and ever alive connection managed by the thread.

actually, i never have written code which tried to reuse a connection since there are always better concepts that would go without.

Sara
0
 
LVL 2

Author Comment

by:Bitlab
ID: 41847168
Thank you, Sara.

Apparently your solution works: I increased timeouts to:

    timeout client          2400s
    timeout server          2400s

and there are no more errors. It may happen on the boundary of 2400, but at least I know now where to troubleshoot.  It looks so simple now.

"if you do so, you never need to reuse but only use the one and ever alive connection managed by the thread. "  I meant this when spoke about "reusing". I meant just checking that socket i is alive by

if ws == None:

means that connection is not closed.

Thanks a lot again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question