Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL server has gone away #121

Open
moneroexamples opened this issue Jan 12, 2019 · 20 comments
Open

MySQL server has gone away #121

moneroexamples opened this issue Jan 12, 2019 · 20 comments

Comments

@moneroexamples
Copy link
Owner

moneroexamples commented Jan 12, 2019

# ERR: SQLException in /home/mwo2/openmonero/src/MySqlAccounts.cpp(select) on line 258
# ERR: MySQL server has gone away
# ERR: SQLException in /home/mwo2/openmonero/src/MySqlAccounts.cpp(insert) on line 285
# ERR: MySQL server has gone away

Sometimes it happens. Don't know yet why.

Previously had simillar problem:

#10

@italocoin-project
Copy link

This could be fixed with force connect check this maybe can help, i haven't encountered this issue maybe because of this

italocoin-project@d34cf46

@moneroexamples
Copy link
Owner Author

Thx. Will check that.

@moneroexamples
Copy link
Owner Author

moneroexamples commented Jan 22, 2019

Thanks. I checked the code and this may work, and will reconnect you. But the problem I see is that the query data will be lost. The code that is calling these queries will not try to re-call it again. So you may end up with missing outputs or inputs in your database after reconnecting in catch part.

I think for reconnection, the better place would be before the query is executed, i.e., where conn->check_if_connected();. So maybe this could be modified, so that it reconnects.

There can also be other reasons why the connection is failing, e.g., default settings in mysql/mariadb being inadequate.

I will try to investigate what's happening. Maybe mysql/mariadb logs will some info about that.

@italocoin-project
Copy link

No problem, i see, this could bring up some problems if it would miss outputs or inputs from mysql DB, but then, if the input gets missed, on a rescan it should be reeaded, because the rescan will find the imputs/outputs from blockchain's db, isn't it? let me know if you find a better way to deal with timeouts, thanks :)

@moneroexamples
Copy link
Owner Author

no problem and yes, would have to rescan to find missing txs/outputs/inputs.

I just setup regular mariadb on my linux box, instead of using docker, and will try to get some logs out of it.

@moneroexamples
Copy link
Owner Author

I added ReconnectOption to mysql, so now it will reconnect when connection drops.

conn = make_shared<MySqlConnector>(
new mysqlpp::ReconnectOption(true));

There still can be a problem, but at least connection should not be dropped permanently. If I manually kill the connection in mariadb I get this, but then it reconnects:

# ERR: SQLException in /home/mwo2/openmonero/src/db/MySqlAccounts.cpp(select) on line 267                                                                                                                                                                                   
# ERR: Lost connection to MySQL server during query  

In the current devel branch I also added Ctrl+C support to greacfully stop openmonero, and the logging got extended.

@italocoin-project
Copy link

italocoin-project commented Jan 22, 2019

You think this option is better then force connect that i've mentioned above?
nice work with Ctrl+C support, great job man.

I have another issue: MDB_READERS_FULL limit
basicaly when i get MANY connections i get the MDB_READERS_FULL limit under heavy load the db leaks readers or something. Did you encountered this problem?

@moneroexamples
Copy link
Owner Author

moneroexamples commented Jan 23, 2019

You think this option is better then force connect that i've mentioned above?

I think so. Its directly implemented in mysql++ and propagated to mysql. It's also recommended in mysql++ docs regarding the timeouts: https://tangentsoft.com/mysqlpp/doc/html/userman/tutorial.html#conn-timeout

Will see how it will work. Can always remove it if its not helpful.

I have another issue: MDB_READERS_FULL limit

I had it maybe only once. It was also reported before: #97

This is one reason why Ctr+C was added. With it, openmoenro will close the lmdb's blockchain database that it opens for reading. You can see this when you run openmonero with -m 3 (level 3 log for monero). This will show you that database is closed properly now when Ctrl+C is detected:

2019-01-23 00:16:01.732     7f8f8095ac00        TRACE   blockchain      src/cryptonote_core/blockchain.cpp:547  Blockchain::deinit
2019-01-23 00:16:01.732     7f8f8095ac00        TRACE   blockchain      src/cryptonote_core/blockchain.cpp:549  Stopping blockchain read/write activity
2019-01-23 00:16:01.732     7f8f8095ac00        TRACE   blockchain.db.lmdb      src/blockchain_db/lmdb/db_lmdb.cpp:1448 BlockchainLMDB::close
2019-01-23 00:16:01.732     7f8f8095ac00        TRACE   blockchain.db.lmdb      src/blockchain_db/lmdb/db_lmdb.cpp:1464 BlockchainLMDB::sync
2019-01-23 00:16:01.733     7f8f8095ac00        TRACE   blockchain      src/cryptonote_core/blockchain.cpp:564  Local blockchain read/write activity stopped successfully
2019-01-23 00:16:01.733     7f8f8095ac00        TRACE   blockchain.db.lmdb      src/blockchain_db/lmdb/db_lmdb.cpp:1178 BlockchainLMDB::~BlockchainLMDB

When you force close it, openmonero has no chance to close the lmdb which it opens and it seems to keep accumulating the open connections. Before I just deleting lmdb.lck (e.g. in home/mwo/.bitmonero/lmdb/lock.mdb) and it solved the problem in my case so that new one is created. Not sure about this though.

Similar issue was also reported before for monero monero-project/monero#2741 with suggested solution.

when i get MANY connections

How many is MANY?

@italocoin-project
Copy link

italocoin-project commented Jan 23, 2019

How many is MANY?

Send more than 126 different login request to openmonero and you will get the issue, let me know

yes, now it actually closes properly, what if it gets killed?

@moneroexamples
Copy link
Owner Author

126 different login request to the mywallet

I see. Probably will need to rethink how lmdb is accessed in openmonero. At the moment, there will be 126 search tx threads accessing the lmdb at the same time. So maybe will have to implement some pooling when only few threads access lmdb at the same time, or move to using rpc to deamon instead of accessing lmdb directly.

what if it gets killed?

Thank it will be like before, all connections, threads will be terminated immedietly. I think it's better to let the all threads, mysql and lmdb close properly when openmonero stops.

@italocoin-project
Copy link

or move to using rpc to deamon instead of accessing lmdb directly

rpc to daemon could solve the problem for good.

maybe will have to implement some pooling when only few threads access lmdb at the same time

It means that someone will have to wait until the threads gets freed again, i think we should test them both

@moneroexamples
Copy link
Owner Author

moneroexamples commented Jan 23, 2019

rpc to daemon should also be much easier to implement, as the second possible solution would require major changes to architecture of openmonero. But rpc will also wont be simultaneous, as is needs also synchronization.

@italocoin-project
Copy link

rpc to daemon should also be much easier to implement, as the second possible solution would require major changes to architecture of openmonero.

I agree

But rpc will also not be simultaneous, as is needs also synchronization.

Thats also true, but i think the best solution is the rpc to daemon, how is mymonero handling with many connections? I assume that they have over 126 consecutive login requests

@moneroexamples
Copy link
Owner Author

mymonero handling with many connections?

Don't know. Their backend is closed sourced. But from what I know they use go and mysql, so I think rpc also would be easiest.

But for mass scale, applications such as openmonero/mymonero are "easily" parallelized, as you can spin up, e.g., 10 instances of the backend and daemons, on 10 servers. One possible way of doing this with some details has already been proposed for openmonero: #95 (comment)

@italocoin-project
Copy link

so I think rpc also would be easiest.

Yes, that would be the best option, do you plan to implement RPC to DAEMON soon? And about more instances, that would be a good idea too, a system to sync all mysql db on all instances would solve the panic in users if they would see that the wallet syncs from 0 again

@moneroexamples
Copy link
Owner Author

Yes, that would be the best option, do you plan to implement RPC to DAEMON soon?

Yes, though "soon" in monero world does not mean anything:-) But yes, this and mysql-thing will be the issues I will be focusing the most at present. When complete? No timeframe on this. Hopefully "soon":-)

Just spin up new branch for that: https://github.com/moneroexamples/openmonero/tree/new_rpc So all new changes will be there for experimentation.

@italocoin-project
Copy link

Nice, i will merge it tomorrow morning and test out the branch, i will let you know if i face issues, thanks :)

@moneroexamples
Copy link
Owner Author

moneroexamples commented Jan 23, 2019

Not sure I will have there anything new for tomorrow, but this is the branch when the rpc changes will be taking place.

No problem. Good you can provide extra info and much needed testing for openmonero. Thanks.

@italocoin-project
Copy link

Thank you for your hard work, i really like your projects and work, you can count on my help for testing out, i use openmonero for my project to, thanks for that :)

@moneroexamples
Copy link
Owner Author

I made a seprate issue for the LMDB readers limit: #127

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

No branches or pull requests

2 participants