a month ago
Hi!
I have a Spring Boot API which sends once a while requests to a Express.js API. I have set the integration between them with using private networking in railway. This have been fine for a while, but all of a sudden the Spring Boot API cannot reach the Express.js API.
In my spring boot API i get org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://discord-bot.railway.internal:3000/alert": null ... Caused by: java.nio.channels.ClosedChannelException: null
And in my Express.js i have
app.post('/alerts', async (req, res) => {and ive experimented with several different app.listen. This i had originally:
app.listen({ port, host: "::", () => {
console.log(`Server listening on port ${port}`);
});But i have tested with having the flag ipv6Only: false also on.
Once i redeploy the express.js application it sometimes works, and sometimes it doesnt. I wonder if it is because of IPv4/IPv6 problems, but i am not sure. Does anyone know how to fix this unstable problem?
Edit: Oh, i have also tried switching to public networking, and that seems to work fine when i have tested.
Pinned Solution
a month ago
your express listen syntax is broken. fix it to:
javascript
const port = process.env.PORT || 3000;
app.listen(port, "::", () => {
console.log(`listening on ${port}`);
});
```
for spring boot, add this environment variable to make java use ipv6 properly:
```
JAVA_OPTS=-Djava.net.preferIPv6Addresses=truerailway's private network uses ipv6 and spring boot defaults to ipv4, which causes the connection issues. this property fixes that
these are both standard documented fixes - the express syntax was definitely wrong and the java property is official oracle documentation for ipv6 connections
i hope this help you 
3 Replies
a month ago
your express listen syntax is broken. fix it to:
javascript
const port = process.env.PORT || 3000;
app.listen(port, "::", () => {
console.log(`listening on ${port}`);
});
```
for spring boot, add this environment variable to make java use ipv6 properly:
```
JAVA_OPTS=-Djava.net.preferIPv6Addresses=truerailway's private network uses ipv6 and spring boot defaults to ipv4, which causes the connection issues. this property fixes that
these are both standard documented fixes - the express syntax was definitely wrong and the java property is official oracle documentation for ipv6 connections
i hope this help you 
ilyassbreth
your express listen syntax is broken. fix it to:javascriptconst port = process.env.PORT || 3000; app.listen(port, "::", () => { console.log(`listening on ${port}`); }); ``` for spring boot, add this environment variable to make java use ipv6 properly: ``` JAVA_OPTS=-Djava.net.preferIPv6Addresses=truerailway's private network uses ipv6 and spring boot defaults to ipv4, which causes the connection issues. this property fixes thatthese are both standard documented fixes - the express syntax was definitely wrong and the java property is official oracle documentation for ipv6 connectionsi hope this help you
a month ago
I think this worked! Thank you. I had the express.js config ealier, but got desperate so i possibly changed to somthing that wasnt valid. But the preferIPv6Addresses=true I didnt know existed.
a month ago
yeah the preferIPv6Addresses=true flag is the key thing most people don't know about when dealing with railway's private networking and java apps. glad it worked out for you!
Status changed to Solved noahd • about 1 month ago
