cybergis / cybergis-compute-core

Apache License 2.0
8 stars 6 forks source link

Typeorm caching breaks data source initialization #122

Closed yianzhang14 closed 1 month ago

yianzhang14 commented 5 months ago

With a new update to the CIGI servers that upgraded the docker version to 26.1.4, data source initialization no longer works correctly on server initialization, giving the error:

Error during Data Source initialization: Error: connect ECONNREFUSED ::1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 6379
}
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: connect ECONNREFUSED ::1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
Emitted 'error' event on Commander instance at:
    at RedisSocket.<anonymous> (/job_supervisor/node_modules/@redis/client/dist/lib/client/index.js:412:14)
    at RedisSocket.emit (node:events:517:28)
    at RedisSocket._RedisSocket_connect (/job_supervisor/node_modules/@redis/client/dist/lib/client/socket.js:166:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Commander.connect (/job_supervisor/node_modules/@redis/client/dist/lib/client/index.js:185:9)
    at async RedisQueryResultCache.connect (/job_supervisor/node_modules/typeorm/cache/RedisQueryResultCache.js:38:17)
    at async DataSource.initialize (/job_supervisor/node_modules/typeorm/data-source/DataSource.js:139:13) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 6379
}

Currently, as a temporary fix, the typeorm caching mechanism was disabled, but it is unclear why exactly this occurred, as commit 64e3c83fe7224e054b3a6ee491f6d270db175cc5 still functions as intended with the typeorm caching.

alexandermichels commented 5 months ago

I merged the patch and pushed to production. On first deployment I got

> node ./production/tools/generate-swagger.js

supervisor server is up, listening to port: 3030
/job_supervisor/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:165
                        return fail(new QueryFailedError_1.QueryFailedError(query, parameters, err));
                                    ^

QueryFailedError: Cannot enqueue Query after invoking quit.
    at Query.<anonymous> (/job_supervisor/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:165:37)
    at Query.<anonymous> (/job_supervisor/node_modules/mysql/lib/Connection.js:526:10)
    at Query._callback (/job_supervisor/node_modules/mysql/lib/Connection.js:488:16)
    at Sequence.end (/job_supervisor/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
    at /job_supervisor/node_modules/mysql/lib/protocol/Protocol.js:236:14
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  query: 'ALTER TABLE `gits` CHANGE `deletedAt` `deletedAt` bigint(6) NULL',
  parameters: undefined,
  driverError: Error: Cannot enqueue Query after invoking quit.
      at Protocol._validateEnqueue (/job_supervisor/node_modules/mysql/lib/protocol/Protocol.js:215:16)
      at Protocol._enqueue (/job_supervisor/node_modules/mysql/lib/protocol/Protocol.js:138:13)
      at PoolConnection.query (/job_supervisor/node_modules/mysql/lib/Connection.js:198:25)
      at /job_supervisor/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:154:36
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    code: 'PROTOCOL_ENQUEUE_AFTER_QUIT',
    fatal: false
  },
  code: 'PROTOCOL_ENQUEUE_AFTER_QUIT',
  fatal: false
}

Node.js v18.18.0

which also appears to stem from typeorm not initializing (let me know if I'm wrong). However, that container crashed and then the next container worked perfectly.

yianzhang14 commented 5 months ago

I think you might just have to run everything twice on a new database if you're trying to reformat it.

I think this happened last time as well with the new version.

alexandermichels commented 4 months ago

Caching currently turned off

yianzhang14 commented 1 month ago

solved: https://stackoverflow.com/questions/72076107/error-connect-econnrefused-13306-is-when-i-try-to-use-typeorm-in-nestjs