bugfix mysql gone away - closing and opening connection when it is needed