sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

uncaught exceptions in the hub -- TypeError: p.sslConfigToPsqlEnv is not a function #7381

Closed williamstein closed 7 months ago

williamstein commented 7 months ago
{
  "id": "892b770a-a9cd-4447-bdd0-38934f131461",
  "event": "uncaught_exception",
  "value": {
    "host": "hub-next-785959f998-pqkp4",
    "error": "TypeError: p.sslConfigToPsqlEnv is not a function",
    "stack": "TypeError: p.sslConfigToPsqlEnv is not a function\n    at i._ensure_database_exists (/cocalc/src/packages/next/.next/server/chunks/6447.js:3:1665)\n    at u.series.r.hosts (/cocalc/src/packages/next/.next/server/chunks/6447.js:1:8168)\n    at /cocalc/src/packages/next/.next/server/chunks/5788.js:7:2770\n    at s (/cocalc/src/packages/next/.next/server/chunks/5788.js:7:5605)\n    at a.forEachOfSeries.a.eachOfSeries (/cocalc/src/packages/next/.next/server/chunks/5788.js:7:5709)\n    at Z (/cocalc/src/packages/next/.next/server/chunks/5788.js:7:2750)\n    at a.series (/cocalc/src/packages/next/.next/server/chunks/5788.js:7:8967)\n    at i._connect (/cocalc/src/packages/next/.next/server/chunks/6447.js:1:8100)\n    at i (/cocalc/src/packages/next/.next/server/chunks/4006.js:1:23988)\n    at t.retry_until_success (/cocalc/src/packages/next/.next/server/chunks/4006.js:1:24632)"
  },
  "time": "2024-03-19T20:51:41.890Z"
}

I don't understand this, but @schrodingersket recently introduced sslConfigToPsqlEnv, so maybe he will?

williamstein commented 7 months ago

NOTE: This doesn't necessarily cause any serious problems at runtime -- it just happened once or twice and could have a "destabilizing influence" and that's not it. So NOT a high priority to fix!

schrodingersket commented 7 months ago

Interesting - this feels like there might be something funky happening with transpilation here. The sslConfigToPsqlEnv function itself is just a simple utility function to transform SSL configuration from this data structure:

https://github.com/sagemathinc/cocalc/blob/3740af523b481aff4bebabf6d99a7667648d4fb7/src/packages/backend/data.ts#L78-L82

...to this one (for the purpose of running a psql command):

https://github.com/sagemathinc/cocalc/blob/3740af523b481aff4bebabf6d99a7667648d4fb7/src/packages/backend/data.ts#L58-L69

I wonder if the data variable name conflicts with something else in that file somehow:

https://github.com/sagemathinc/cocalc/blob/7131a6be6687a2a0e68644bdda138ba3654e3f38/src/packages/database/postgres-base.coffee#L45

It's also possible that CoffeeScript doesn't like export const function types, which is how sslConfigToPsqlEnv is defined.

At any rate, I've opened a small PR (in draft state - it's tested, but would appreciate another set of eyes before merge) that addresses both of those possibilities, but I'm not sure I could confidently speak to why the above stack trace is happening without seeing whether we can obtain more context about when it happens. It's also possible that this PR could force whatever is causing the error to throw on import instead of when _ensure_database_exists is called, so that's probably a good thing to keep in mind.