pg-boss failed to start!

Hey guys, I'm pretty new to Wasp (first day) and also have little experience with Node.js. All my web experience was with Python (Flask). I installed Wasp and created a project based on SaaS, at first everything ran very well, I was able to configure the login through Google and everything worked perfectly. I went to restart the server and after that it keeps giving an error in pg-boss and it seems that it is not starting the node server. I thought I had made some changes to the files but no. I even created another project from scratch and it kept having the same error. The strange thing is that I restarted Wasp several times and in one of the times it gave this error and now every time it starts it gives the same error. I already restarted the db and even the computer. can anybody help me? ā€œ [Server] šŸš€ "Google" auth initialized [Server] Starting pg-boss... [Server!] pg-boss failed to start! [Server!] Error: connect ECONNREFUSED ::1:5432 [Server!] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) { [Server!] errno: -61, [Server!] code: 'ECONNREFUSED', [Server!] syscall: 'connect', [Server!] address: '::1', [Server!] port: 5432 [Server!] } [Server] Server listening on port 3001 [Server!] node:internal/process/promises:288 [Server!] triggerUncaughtException(err, true /* fromPromise */); [Server!] ^ [Server!] [Server!] [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<PgBoss>".] { [Server!] code: 'ERR_UNHANDLED_REJECTION' [Server!] } [Server!] [Server!] Node.js v18.16.0 [Server] [nodemon] app crashed - waiting for file changes before starting... ā€œ
59 Replies
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
Hey. Can you share your wasp file?
martinsos
martinsosā€¢2y ago
@Cyberdine , based on this part of the message Error: connect ECONNREFUSED ::1:5432, I would say that PG-boss failed to connect to the postgres database! What you need is postgres database running on port 5432 that Wasp knows how to connect to. Check our docs for instructions on how to get one running: https://wasp-lang.dev/docs/language/features#postgresql -> easiest is by just running wasp start db.
shayne
shayneā€¢2y ago
Yep I would agree with @martinsos this seems like a DB connectivity issue. It's just that pg-boss is the first to notice it. Maybe you can try the Wasp DB command @Cyberdine?
Cyberdine
Cyberdineā€¢2y ago
Hello everyone, first thanks for the help. Yes, I'm running the wasp start db command, I managed to run the whole project a few times, but in one of the resets it started giving this error. I even reinstalled everything and started another project. But the error persists. I'll send some print screens below.
Cyberdine
Cyberdineā€¢2y ago
No description
Cyberdine
Cyberdineā€¢2y ago
No description
Cyberdine
Cyberdineā€¢2y ago
WASP is the template's original, I haven't made any changes to it.
hometechdad
hometechdadā€¢2y ago
I had a similar issue. I may be wrong, but I believe pg-boss is used for jobs (like cron jobs sending emails). This may not be the best solution, but for me, I did not need this functionality. So, I commented out the job emailChecker code at the bottom of the main.wasp file. It resolved that error for me (for now)...
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
Yeah. My guess is that by looking at your Wasp file, that you haven't set up SendGrid emailing. You may want to comment out/remove the auth.email method on lines 18-32, as well as lines 214-223, of your wasp file. once you've created an account on SendGrid and added your API key to the env.server file, you'll want to make sure to configure those settings with the email address you used to create that account
martinsos
martinsosā€¢2y ago
@Cyberdine so as others said, one thing you can do is comment out the piece of code that actually needs pg-boss, which is jobs, so job emailChecker and that should circumvent the error, if it is only connected to the pg-boss and not the database all together. But, the question is still why error happens in the first place. It looks from the wasp start db like your db is running with no issues, but then pg-boss complains that it can't connect to the database, that is pretty weird, sorry about that! Couple of questions that might help: 1. What is your setup: which OS, is there anything unusual about it (e.g. you are running everything inside a docker or inside some vm or smth)? 2. Just to double-confirm: you do leave wasp start db running while also running wasp start in parallel, right? One needs to be running in one terminal window/tab, second in another. 3. What if you run wasp db studio in parallel to wasp start db , does studio work? It should open an app in browser that shows your database. Can you remember, did you actually have this problem with pg-boss? Or can you try it again, enabling job emailChecker and see if that causes you problems? Because I have been basing my debugging here so far assuming that probably the whole database is not running and that pg-boss is just the one hitting that issue, but if for you everything works when pg-boss is disabled, that means we have actual pg-boss issue that we need to investigate.
Cyberdine
Cyberdineā€¢2y ago
I commented out these lines, but now I get another error
MEE6
MEE6ā€¢2y ago
Wohooo @Cyberdine, you just became a Waspeteer level 1!
Cyberdine
Cyberdineā€¢2y ago
No description
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
ah, maybe its best to leave the email auth the way it us only comment out the job
Cyberdine
Cyberdineā€¢2y ago
1. I'm running MacOS Ventura (13.2.1), I'm running it straight from my terminal, without Docker. As far as I understand the database is running inside a docker, according to instructions from the SaaS template repository. 2. Yes, exactly 3. I ran the studio and it was normal, it opened the browser at the address: http://localhost:5555/
Cyberdine
Cyberdineā€¢2y ago
Now it's working šŸ™‚
No description
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
yes. if you read the previous error it says that it couldn't find the typescript types associated with the functions in src/server/auth/email.ts so probably your pg-boss issue will be solved once you sign up with SendGrid and configure it in the template correctly
Cyberdine
Cyberdineā€¢2y ago
Great One last question that may seem pretty basic. It's the first time I'm working on this project structure, as I've always worked with the back-end in Flash and used HTML/JS/CSS on the front. When I'm in the project I realized that there are some "same" files inside different folders. Like for example actions.ts that has inside /src/server but also seems to have the same file inside /.wasp/out/server/src/ext/src, in this case what would that be? which one should I edit/work on? Sorry if the question seems silly.
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
not silly at all. all your work should be in the root of the project, like on your main.wasp config file, and in src you generally don't want or need to go into the .wasp folder. These are the files that wasp is compiling for you. If you're curious what wasp is doing for you in the background, you can take a peek in there, but remember not to edit anything in these files if you do manage to ruin something, you can always run wasp clean and then wasp start again, and wasp will reinstall and recompile everything for you for a fresh start
Cyberdine
Cyberdineā€¢2y ago
Perfect, now it's very clear and simple. I was a bit overwhelmed with the amount of files inside the .wasp hehehe.
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
yeah. check out the ToDo App tutorial. You might want to run through that first. Will only take about 30 minutes. That will teach you the most important parts of wasp and everything will make a lot more sense: https://wasp-lang.dev/docs/tutorials/todo-app
Introduction | Wasp
If you want to run Wasp locally and haven't yet set it up, check out Getting Started first for installation instructions, and then continue with the tutorial.
martinsos
martinsosā€¢2y ago
Yup as @Vinny (@Wasp) explained, .wasp is not for you to touch -> it is kind of like when C++ is compiled to assembly, where .wasp would be the assembly. It is also why it is .gitignored. Ideally, you wouldn't even need to know .wasp exists, but sometimes it can be useful to take a peek when debugging. @shayne (for pg boss) @Vinny (@Wasp) @Filip (for ts) @miho (for auth) what shall we do with these errors that @Cyberdine encountered? pg boss one, there is certainly something wrong there, right? What about the types one, that also doesn't sound right?
miho
mihoā€¢2y ago
tsc picks up all of the TS files even if not used in the Wasp project. In this case tsc picked up the e-mail auth customisation functions while email auth was disabled (and not types were generated for it). That's a tricky one, but we would need to change our build process from using tsc to using something that's "usage aware" and only compile files that are used.
hometechdad
hometechdadā€¢2y ago
I uncommented that section and the app started up fine. I think @Vinny (@Wasp) was correct. When I first tried, I did not have sendgrid setup.
shayne
shayneā€¢2y ago
I have tried to repro the pg-boss erorr with this sass gtp template, but the only way I can get that error is if the DB is not running. if i run wasp db start or via my local native Postgres on Mac, it starts up fine. šŸ¤” and just a quick final clarification. for everyone with the pg-boss connection error, with your database running and re-enabling it, does it still fail for you?
MEE6
MEE6ā€¢2y ago
Wohooo @shayne, you just became a Waspeteer level 31!
martinsos
martinsosā€¢2y ago
But it sounds very weird that sendgrid would have anything to do with pg-boss hm!
IamIconLiving
IamIconLivingā€¢2y ago
is this @Vinny (@Wasp) 's SaaS boilerplate with stripe etc? if so, I don't have sendgrid configured and had no issues with it
Filip
Filipā€¢2y ago
We've talked about this but didn't come up with a proper solution yet. I guess it's time we do šŸ˜…
Cyberdine
Cyberdineā€¢2y ago
I don't know if it helps, but as I said the first few times I ran the project, it went without any problems and I still hadn't configured Sendgrid. After that I started messing with the html to make some visual adjustments and in one of the refreshes this error started to happen. And after that nothing resolved, except commenting the code you suggested.
martinsos
martinsosā€¢2y ago
That is very weird, I am hoping that something additional happened, that is just not very obvious now. We will keep our eyes open for this, in case it happens again to somebody! Thanks @Cyberdine !
Cyberdine
Cyberdineā€¢2y ago
Hello everyone, how are you? I am back. I created a key in Sendgrid and put it in my env file. I uncommented the recommended part in the wasp file. But I'm still having the same error. With the Sendgrid key but with the commented emailChecker job I don't get any errors. So I think there is no relation with the Sendgrid key, what is causing the problem is the emailChecker.
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
Do you have it configured with the email address you used to create your sendgrid account? If so, try running wasp clean and then wasp start again
Cyberdine
Cyberdineā€¢2y ago
Yes, I set it up and emails are being sent normally. The big problem is when I uncomment the emailChecker job. I tried wasp clean and the problem persists when I uncomment the emailChecker lines
MEE6
MEE6ā€¢2y ago
Wohooo @Cyberdine, you just became a Waspeteer level 2!
Cyberdine
Cyberdineā€¢2y ago
No description
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
how are you running your database?
martinsos
martinsosā€¢2y ago
@Cyberdine so we are again on that same problem! Would be great if we could replicate it on our side. Is there a way possibly that you share with us the version of the code that doesn't work and we try to run it? Either what you have if you are comfortable sharing that, or even better if you can cut that one down, take out all the functionality that is not needed to reproduce error, and send us that, so called "minimal reproducible example", and we can try it on our side.
Cyberdine
Cyberdineā€¢2y ago
I'm running with the command "wasp start db", and as far as I understand it's running inside a docker. To help you with more information, everything works perfectly. I have no problems with the project, I can register users, login, logout and so on. So I don't think there are problems with the database. I can also transact on Stripe without any problems. When registering users receive email normally and etc. The problem really is when I uncomment the emailChecker job. I think the easiest thing to do would be for me to just send you the template hehehe. Since this occurs even using the original template without any modifications. Anyway, this has not affected me to build my project, because I have no plans to use the emailChecker job. I'm submitting it here because I'm really enjoying Wasp and I want to contribute as best I can to the project.
shayne
shayneā€¢2y ago
maybe we could schedule a quick virtual meeting/screenshare sometime then just to double check things and gather more info if you are ok with that?
martinsos
martinsosā€¢2y ago
Thanks, that does help! Ok, if it happens in the original template as it is, that already helps with reproduction. The tricky thing is that you said it wasn't happening at first and then it started happening + to us it didn't happen, which means it is not so easy to reproduce hm. If you have normal OS and setup on it, and you use vanilla template for SaaS, then the only thing remaining is some configuration, that must be the issue. Tricky!
Cyberdine
Cyberdineā€¢2y ago
I re-ran the whole process and recorded my screen. The error happens from the first time actually. What must have happened is that the first time I ran the project I wasn't familiar with the terminal and so on. And I probably wasn't looking at the terminal to see if there were any errors and I was just modifying the html. But in fact the problem happens from the first time. I'm uploading the video on YouTube and I'll send it here soon.
shayne
shayneā€¢2y ago
this was super helpful, thanks @Cyberdine we will try to repro given this now šŸ‘
Vinny (@Wasp)
Vinny (@Wasp)ā€¢2y ago
I probably built the saas template while using a railway hosted postgres db. just for your reference, shayne
shayne
shayneā€¢2y ago
I already tried it with wasp db and it was fine on linux earlier this week, I will retry on Mac though today sorry one last Q @Cyberdine what version of wasp are you running? thanks! šŸ™
Cyberdine
Cyberdineā€¢2y ago
No description
shayne
shayneā€¢2y ago
thanks
zFish
zFishā€¢11mo ago
I've the same problem, is there any updates for this?
martinsos
martinsosā€¢11mo ago
Hey @zFish , would you mind providing a bit more details on this? THere are different problems discussed inthis thread, but I assumed you are referring to the problem where suddenly pg-boss starts throwing errors after restarting wasp? Would be great if you could let us know exact steps that led to this, it will help us to replicate it. Also, what is your: - OS - Wasp version - node/npm version
zFish
zFishā€¢11mo ago
Thanks @martinsos Here are my steps: 1. wasp start db 2. wasp start The client can start but the server failed as the image shows. The wasp version is: 0.11.8
No description
zFish
zFishā€¢11mo ago
And this is my main.wasp file.
martinsos
martinsosā€¢11mo ago
Thanks for the details! What about OS version and node / npm version, would you mind sharing that? And how did you get to this? So did you get this error from the very start? Or did it start appearing after some steps? If so, which steps?
zFish
zFishā€¢11mo ago
My OS is macOS M1, and the node version is v18.15.0, the npm is 9.5.0, I just install the wasp by following the docs and there is no any other issues, just use wasp to start
martinsos
martinsosā€¢11mo ago
Thanks @zFish , we will be looking into this! We will try to replicate it in the following days and will let you know how it goes. In the meantime, one additional potentially crucial piece of information that could help us a lot are logs from wasp start db -> could you please provide those? So output you get once you run wasp start db, all of it. Also, does wasp db studio work for you? While wasp db start is running.
miho
mihoā€¢11mo ago
Hey @zFish could you please try running the following minimal example app I put together? šŸ™‚ It has two things: - it tries to run some PgBoss job - it tries just to connect to a Postgres DB If you could please download and unzip it. Then npm install then check out the README.md for a command to run the database with Docker. After that please run the two tests by running: - first npm start - then npm run second-test Please report back when you have time šŸ™‚
zFish
zFishā€¢10mo ago
Thanks @martinsos @miho I fixed it by updating the database URL from localhost to 127.0.0.1, it seems the node can not resolve the localhost.
MEE6
MEE6ā€¢10mo ago
Wohooo @zFish, you just became a Waspeteer level 1!
martinsos
martinsosā€¢10mo ago
Interestign! I wonder why that suddenly started happening, if it wasn't happening before, and how was that related to pg-boss!
Want results from more Discord servers?
Add your server