slush0 / stratum

Stratum server implementation using Python Twisted
Other
89 stars 131 forks source link

protocol.py - lineReceived() causes connection resets for stratum-mining #1

Closed liferealized closed 11 years ago

liferealized commented 11 years ago

Looks like cgminer sometimes sends through data that cannot be loaded by the json library. This ends up throwing an error at line 185 in protocol.py and the connection is closed.

Can there be some type of setting to trap this error in stratum? Or is there another way to catch the error before it ends up closing the connection?

slush0 commented 11 years ago

Can you sniff what exactly sends cgminer? Maybe report bug to ckolivas would be better solution?

The best option is to fix cgminer. Second best option is to close the connection and let miner to bootstrap correct connection again. Third option is to let miner developers write bugged code and do many workarounds and heuristics to fix it for them.

slush0 commented 11 years ago

Oh, you're asking me HOW to sniff the problem. Well, what kind of exception it throws?

liferealized commented 11 years ago

http://pastebin.com/Y8tSjrVs

slush0 commented 11 years ago

We won't find anything more than this: {"params": ["gigavps.000", "15", "98010000", "XT��a2e50", "f2467e7e"], "id": 3437, "method": "mining.submit"}

Please report this to ckolivas, there's some buffer overflow in cgminer. These binary data ("??") should not be there.

liferealized commented 11 years ago

I understand it shouldn't be there, but I don't control conman. So I'll ask again, is there a way to catch this error through stratum-mining so the connection doesn't close?

slush0 commented 11 years ago

Quick and dirty hack is to modify code in protocol.py, around line 185 to look like this:

request_counter.finish() log.exception("Processing of message failed")

return error.ConnectionLost('Processing of message failed')

(added "#" to "return error....")

But it may lead to unexpected behaviour, so I warned you :-).

Please, still report this to conman, to help fix the bug in upstream.

slush0 commented 11 years ago

Hm, actually I don't think this hack will really work, because Stratum server should respond by message to every received message (or close the connection, which you dislike). So I think this will lead to complete crash of cgminer, because he'll stack requests...

slush0 commented 11 years ago

Btw what's your cgminer version and on what platform are you running? I'll point conman here.

liferealized commented 11 years ago

2.10.4

https://bitcointalk.org/index.php?topic=28402.msg1468932#msg1468932

I'll hack around with stratum as you suggested. Maybe i'll figure out a way to configure it from stratum-mining.