dropbox / securitybot

Distributed alerting for the masses!
Apache License 2.0
994 stars 112 forks source link

SQLEngine: Too many connections #17

Open nstr10 opened 7 years ago

nstr10 commented 7 years ago

I've followed the setup instructions in a fresh virtualenv and tried to run main.py It connects to the Slack API successfully, creates securitybot, loads configuration, and starts the RTM session. Then it issues a couple hundred warnings "Recovering from lost MySQL connection" and crashes. Here is a truncated traceback:

Traceback (most recent call last):
  File "main.py", line 45, in <module>
    main()
  File "main.py", line 41, in main
    sb = SecurityBot(chat, tasker, duo_builder, REPORTING_CHANNEL, 'config/bot.yaml')
  File "/securitybot/securitybot/bot.py", line 95, in __init__
    self.blacklist = SQLBlacklist()
  File "/securitybot/securitybot/blacklist/sql_blacklist.py", line 17, in __init__
    names = SQLEngine.execute('SELECT * FROM blacklist')
  File "/securitybot/securitybot/sql.py", line 79, in execute
    return SQLEngine.execute(query, params)

Those last two lines repeat a couple hundred times and then

  File "/securitybot/securitybot/sql.py", line 78, in execute
    SQLEngine._db)
  File "/securitybot/securitybot/sql.py", line 51, in _create_engine
    db=db)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1040, 'Too many connections')

While the user defined on line 93 of sql.py (why is this setting buried?) has full rights to the database, no tables are created.

bryaninabox commented 7 years ago

Have you tried initializing the database with db_up.py? https://github.com/dropbox/securitybot/blob/master/util/db_up.py

nstr10 commented 7 years ago

That seems to have done the trick. Might be a good idea to include that in the instructions along with more detailed information on where exactly user, password, and DB location information should be placed. I added them to both db_up.py and sql.py's init_sql function.

bryaninabox commented 7 years ago

Great! Thanks for the suggestion - this is definitely something that should be in our README. I'll create a PR for this when I have a few spare cycles