Flask + Beaker 사용 시 "MySQL server has gone away" 


  • 내용 
    • 관리자 사이트 개발 시 다음날 아침에 접속하려고 할 때 "OperationalError: (pymysql.err.OperationalError) (2006, "MySQL server has gone away (error(32, 'Broken pipe'))") [SQL: u'SELECT beaker_cache.data \nFROM beaker_cache \nWHERE beaker_cache.namespace = %(namespace_1)s'] [parameters: {u'namespace_1': '5640182909d9482fa42baa6f52fa57e9'}]" 에러내용을 확인.
  • 원인
    •  Beaker 사용 시 'session.type'을 'ext:database'를 사용하고 pymysql을 통해서 접근할 때, MySQL Connection이 생성되는데 이 때 'wait_timeout'이 만큼 sleep이 경과되고 MySQL connection이 제가거 되고 난 뒤에 다시 접근할 때 "MySQL server has gone away" 에러 발생
  • 조치
    • beaker session option의 'sa.pool_recycle' 활용
    • 'wait_timeout'보다 적은 시간 만큼 request 요청하기 (crontab, health check 등)

  • 조치1(pool_recycle 사용)
session_opts = {
'session.sa.pool_recycle': 250
}


  • 조치2(crontab 사용)
0 */3 * * * /usr/lib/python/python2.7 {경로}/crontab.py





'개발 > Python' 카테고리의 다른 글

Python isinstance Decimal 확인 오류  (0) 2019.03.20
pymssql transaction없이 실행  (0) 2019.03.05
pip 설치시 SSL 에러  (0) 2018.09.10
db migrate 에러 관련 사항(SQLAlchemy)  (0) 2018.09.10
db column 변경(SQLAlchemy)  (0) 2018.09.10

+ Recent posts