I regularly check the amount of memory I have used for my nodejs project from the RailwayApp Dashboard.
For the last 2 weeks I've been observing strange memory spikes with no problems with my code.
I did this test on my own computer, but I could not observe any increase.
Addendum: I am using Nixpacks in my RailwayApp project. (no alternative options/not active)
#Pointless memory increase :/
44 messages · Page 1 of 1 (latest)
Project ID: 58c83e7e-5267-460d-8b9a-4b9f4ca7abe7
You might find these helpful:
⚠️ experimental feature
funny thing is that this is one thing I literally pull my brains out all the time. There are many reason for random memory spikes though, like how sometimes the project may not return RAM back to the system
Issue also may be memory leaks from libraries you may be using (this was true for some my python subprocess projects within NodeJS). In this case updating or downgrading the libraries typically solves the problem.
There are some ways to tell NodeJS to use less memory with V8's flags at https://flaviocopes.com/node-runtime-v8-options/
This is still an active issue I am still facing though I hope all these may help you
It likely has to do with the monitoring software
There’s been bugs before where it shows it as cumulative for some reason
It’s just funky software
Are you talking about Railway's metrics implementation?
That issue has been fixed. If there's spikes in usage then it's an issue with your code.
Like 2 weeks ago yeah
something along the lines of JavaScript native bcrypt hashing, something that is short lived but memory intensive
just an example, might spark some ideas
calculating strong etags by buffering body into memory, there's so many possibilities
Yes,
I was replying to what Alex said above, they called it software which confused me
it’s not software
I'm constantly checking the code, there's no extra module I'm using, nothing looping
consensus is it’s an issue with your code/a memory leak with a package you’re using
or this
whatever it is it’s not Railway
I think I found the source of the problem, I haven't observed an increase for a few hours
app.use(session({ secret: config.cryptrSecretKey, resave: false, saveUninitialized: false, cookie: { expires: 8640000 } }))
app.use((req, res, next) => {
req.session.ip = req.ip.startsWith('::') ? '0.0.0.0' : req.ip; //THE PROBEM LINE
const domain = "cihatksm.com";
if (req.session.ip == "0.0.0.0") return next();
if (req.headers.host.startsWith("www") || req.headers.host !== domain)
return res.redirect("http://" + domain + req.url);
return next()
})```
new code:
```js
app.use((req, res, next) => {
let ip = req.ip.startsWith('::') ? '0.0.0.0' : req.ip;
const domain = "cihatksm.com";
if (ip == "0.0.0.0") return next();
if (req.headers.host.startsWith("www") || req.headers.host !== domain)
return res.redirect("http://" + domain + req.url);
return next()
})
app.use(session({ secret: config.cryptrSecretKey, resave: false, saveUninitialized: false, cookie: { expires: 8640000 } }))```
I don't fully understand why this causes memory increase. 😄
Thank you for your help
so at least I was in the ballpark with my guesses, glad you got it solved!
hey making fun of peoples code is my job

let is only for variables that need to be mutated or reassigned
const will let you mutate most things but its cringe and not good
eslint will scream at you for doing either
Don’t use let, use const
Let is for variables that you want to reassign or mutate
Const is for variables that never get reassigned or retyped or mutated
It’s to stop you from accidentally reassigning a variable which never needs to be
🤨
I know I told you that I'm bad at code, but I know that stuff at least believe it or not, but you said const was cringe, hence my confusion
Mutating variables is cringe