File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,8 @@ export interface MySqlConnectionConfig {
151
151
export default class MySQLDriver implements BaseDriver {
152
152
db ?: Pool ;
153
153
connectionString : MySqlConnectionConfig ;
154
+ keepAliveTimer : NodeJS . Timeout | null = null ;
155
+ isPinging = false ;
154
156
155
157
constructor ( connectionString : MySqlConnectionConfig ) {
156
158
this . connectionString = connectionString ;
@@ -160,6 +162,10 @@ export default class MySQLDriver implements BaseDriver {
160
162
if ( this . db ) {
161
163
await this . db . end ( ) ;
162
164
}
165
+
166
+ if ( this . keepAliveTimer ) {
167
+ clearInterval ( this . keepAliveTimer ) ;
168
+ }
163
169
}
164
170
165
171
protected async getConnection ( ) {
@@ -170,7 +176,25 @@ export default class MySQLDriver implements BaseDriver {
170
176
dateStrings : true ,
171
177
pool : { min : 1 , max : 1 } ,
172
178
connectionLimit : 1 ,
179
+ enableKeepAlive : true ,
173
180
} ) ;
181
+
182
+ this . keepAliveTimer = setInterval ( ( ) => {
183
+ if ( this . isPinging ) return ;
184
+
185
+ this . isPinging = true ;
186
+ this . db
187
+ ?. getConnection ( )
188
+ . then ( ( conn ) => {
189
+ conn . ping ( ) ;
190
+ conn . release ( ) ;
191
+ } )
192
+ . catch ( console . error )
193
+ . finally ( ( ) => {
194
+ this . isPinging = false ;
195
+ } ) ;
196
+ } , 6000 ) ;
197
+
174
198
return this . db ;
175
199
}
176
200
You can’t perform that action at this time.
0 commit comments