Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot failing to start: TypeError: glob.sync is not a function #376

Closed
richardlau opened this issue Mar 7, 2023 · 11 comments · Fixed by #377
Closed

Bot failing to start: TypeError: glob.sync is not a function #376

richardlau opened this issue Mar 7, 2023 · 11 comments · Fixed by #377

Comments

@richardlau
Copy link
Member

@tniessen reports that Jenkins status is still not being posted to pull requests.

Looking at https://ci.nodejs.org/job/post-build-status-update runs, e.g. https://ci.nodejs.org/job/post-build-status-update/1837783/flowGraphTable/, I can see that although the jobs are green, the HTTP request to the bot has failed:
image

https://ci.nodejs.org/job/post-build-status-update/1837783/execution/node/17/

hudson.AbortException: Fail: Status code 408 is not in the accepted range: 100:399

If I log into the server for the github-bot, I can see that the service isn't running:

root@infra-rackspace-debian8-x64-1:~# systemctl status github-bot
● github-bot.service - github-bot
   Loaded: loaded (/lib/systemd/system/github-bot.service; enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2023-03-07 12:19:55 UTC; 41ms ago
  Process: 25524 ExecStart=/usr/bin/node server.js (code=exited, status=1/FAILURE)
 Main PID: 25524 (code=exited, status=1/FAILURE)

Mar 07 12:19:55 infra-rackspace-debian8-x64-1 systemd[1]: github-bot.service: main process exited, code=exited, status=1/FAILURE
Mar 07 12:19:55 infra-rackspace-debian8-x64-1 systemd[1]: Unit github-bot.service entered failed state.
root@infra-rackspace-debian8-x64-1:~#

and from the syslog:

Mar  7 12:13:26 infra-rackspace-debian8-x64-1 systemd[1]: Started github-bot.
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: /home/iojs/github-bot/server.js:13
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: glob.sync(scriptsToLoad).forEach((file) => {
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: ^
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: TypeError: glob.sync is not a function
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at Object.<anonymous> (/home/iojs/github-bot/server.js:13:6)
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at Module.load (internal/modules/cjs/loader.js:928:32)
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 node[24754]: at internal/main/run_main_module.js:17:47
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 systemd[1]: github-bot.service: main process exited, code=exited, status=1/FAILURE
Mar  7 12:13:26 infra-rackspace-debian8-x64-1 systemd[1]: Unit github-bot.service entered failed state.
@richardlau
Copy link
Member Author

#372 is the most likely suspect. cc @Trott

richardlau added a commit that referenced this issue Mar 7, 2023
glob@9 no longer exports `sync()`.

Fixes: #376
Refs: isaacs/node-glob#493
@richardlau
Copy link
Member Author

PR (untested): #377

richardlau added a commit that referenced this issue Mar 7, 2023
glob@9 no longer exports `sync()`.

Fixes: #376
Refs: isaacs/node-glob#493
Refs: #372
@richardlau richardlau reopened this Mar 7, 2023
@richardlau
Copy link
Member Author

bot still fails to start. Now getting:

Mar  7 17:15:12 infra-rackspace-debian8-x64-1 systemd[1]: Starting github-bot...
Mar  7 17:15:12 infra-rackspace-debian8-x64-1 systemd[1]: Started github-bot.
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: {"name":"bot","hostname":"infra-rackspace-debian8-x64-1","pid":1969,"level":30,"msg":"Loading: scripts/ping.js","time":"2023-03-07T17:15:13.365Z","v":0}
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: internal/modules/cjs/loader.js:883
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: throw err;
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: ^
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: Error: Cannot find module 'scripts/ping.js'
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: Require stack:
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: - /home/iojs/github-bot/server.js
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Function.Module._load (internal/modules/cjs/loader.js:725:27)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Module.require (internal/modules/cjs/loader.js:952:19)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at require (internal/modules/cjs/helpers.js:88:18)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at /home/iojs/github-bot/server.js:15:3
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Array.forEach (<anonymous>)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Object.<anonymous> (/home/iojs/github-bot/server.js:13:25)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: at Module.load (internal/modules/cjs/loader.js:928:32) {
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: code: 'MODULE_NOT_FOUND',
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: requireStack: [ '/home/iojs/github-bot/server.js' ]
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 node[1969]: }
Mar  7 17:15:13 infra-rackspace-debian8-x64-1 systemd[1]: github-bot.service: main process exited, code=exited, status=1/FAILURE

@richardlau
Copy link
Member Author

I'm guessing we're somehow being affected by

More correct handling of ** vs ./**, following Bash semantics, where a ** is followed one time only if it is not the first item in the pattern.

(https://github.com/isaacs/node-glob/blob/main/changelog.md#performance-and-algorithm-changes)

github-bot/server.js

Lines 9 to 16 in 7f2b20b

const scriptsToLoad = process.env.SCRIPTS || './scripts/**/*.js'
const { app, events } = require('./app')
// load all the files in the scripts folder
globSync(scriptsToLoad).forEach((file) => {
logger.info('Loading:', file)
require(file)(app, events)
})

@Trott

This comment was marked as outdated.

@Trott
Copy link
Member

Trott commented Mar 7, 2023

(A test that just ran node server.js would have found this.)

@richardlau
Copy link
Member Author

richardlau commented Mar 7, 2023

I'm speculating that we're no longer getting paths prefixed with ./ back from glob.
e.g. instead of ./scripts/ping.js we're now getting scripts/ping.js and that does affect how require() works.

@Trott
Copy link
Member

Trott commented Mar 7, 2023

Indeed, this fixes it:

diff --git a/server.js b/server.js
index b3aa5b6..db7a7a9 100644
--- a/server.js
+++ b/server.js
@@ -12,7 +12,7 @@ const { app, events } = require('./app')
 // load all the files in the scripts folder
 globSync(scriptsToLoad).forEach((file) => {
   logger.info('Loading:', file)
-  require(file)(app, events)
+  require(`./${file}`)(app, events)
 })
 
 app.listen(port, () => {

@richardlau
Copy link
Member Author

isaacs/node-glob#495

@richardlau
Copy link
Member Author

Ah, there's a new dotRelative option isaacs/node-glob#500

@richardlau
Copy link
Member Author

Bot has started with #378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants