next-auth get session fails with ECONNREFUSED - session

I'm using ingress nginx to deploy my app to kubernate with hostname bakugallery.com.
I use getSession inside the getServerSideProps as below.
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
const session = await getSession(context)
console.log('session', session)
if (!session) {
context.res.writeHead(302, { Location: '/' })
context.res.end()
return {
props: {
user: null,
}
}
}
return {
props: {
user: session?.user,
},
}
}
And getting session fails with connect ECONNREFUSED 127.0.0.1:443. Below is the stacktrace.
https://next-auth.js.org/errors#client_fetch_error request to https://bakugallery.com/api/auth/session failed, reason: connect ECONNREFUSED 127.0.0.1:443 {
[client] error: {
[client] message: 'request to https://bakugallery.com/api/auth/session failed, reason: connect ECONNREFUSED 127.0.0.1:443',
[client] stack: 'FetchError: request to https://bakugallery.com/api/auth/session failed, reason: connect ECONNREFUSED 127.0.0.1:443\n' +
[client] ' at ClientRequest.<anonymous> (/app/node_modules/next/dist/compiled/node-fetch/index.js:1:65756)\n' +
[client] ' at ClientRequest.emit (node:events:513:28)\n' +
[client] ' at TLSSocket.socketErrorListener (node:_http_client:494:9)\n' +
[client] ' at TLSSocket.emit (node:events:513:28)\n' +
[client] ' at emitErrorNT (node:internal/streams/destroy:157:8)\n' +
[client] ' at emitErrorCloseNT (node:internal/streams/destroy:122:3)\n' +
[client] ' at processTicksAndRejections (node:internal/process/task_queues:83:21)',
[client] name: 'FetchError'
[client] },
[client] url: 'https://bakugallery.com/api/auth/session',
[client] message: 'request to https://bakugallery.com/api/auth/session failed, reason: connect ECONNREFUSED 127.0.0.1:443'
[client] }
It says request to https://bakugallery.com/api/auth/session failed, but when I manually access this url with brower, it works fine.
Any idea how to fix this?

Related

Receiving error message when trying to connect to GraphQL api over websocket using k6

I'm going to perform a subscription test using k6 for the graphql api that uses Hasura. Here's what I've tried:
import ws from "k6/ws";
import { check } from "k6";
export const myFunc = (url, access_token, id, query) => {
const headers = {
Authorization: access_token,
};
const res = ws.connect(url, { headers }, function (socket) {
socket.on("open", function open() {
console.log(`VU ${__VU}: connected`);
socket.send(
JSON.stringify({
type: "connection_init",
payload: headers,
})
);
console.log("sending query");
socket.send(
JSON.stringify({
type: "start",
payload: {
query: query,
variables: {
id,
}
},
})
);
});
...
socket.on("message", function (msg) {
console.log(`VU ${__VU}: received message: ${msg}`);
const message = JSON.parse(msg);
if (message.type == "connection_ack")
console.log("Connection Established with WebSocket");
if (message.type == "data") console.log(`Message Received: ${message}`);
});
...
};
And the logs with error:
INFO[0001] VU 1: connected source=console
INFO[0001] sending query source=console
INFO[0001] VU 1: received message: {"type":"ka"} source=console
INFO[0001] VU 1: received message: {"type":"connection_ack"} source=console
INFO[0001] Connection Established with WebSocket source=console
INFO[0001] VU 1: received message: {"type":"ka"} source=console
INFO[0001] VU 1: received message: {"type":"connection_error","payload":"parsing ClientMessage failed: Error in $: When parsing the record StartMsg of type Hasura.GraphQL.Transport.WebSocket.Protocol.StartMsg the key id was not present."} source=console
Why am I receiving the key id not present error? I have no idea what that means and couldn't find anything when I searched for it.
When you send a message over established websocket connection, the protocol dictates that you need to send id too. See this link.
Example payload:
{
"id": "1",
"type":"start",
"payload": {
"variables":{},
"query":"query MyQuery {\n test {\n id\n }\n}\n"
}
}
id can be any string decided by the client. When server send the response back, it will contain the same id. With parsing ClientMessage failed error message, Hasura is complaining that it cannot find the id.

Problem with infura.io gateway requiring auth posting to IPFS

Before Oct 2022, Infura.io allow users to post using its gateway as follows: No auth is required. My original code is as follows in ipfs.js file.
const IPFS = require('ipfs-api');
const ipfs = new IPFS({host: 'ipfs.infura.io', port: 5001, protocol: 'https'});
export default ipfs;
When auth is needed I included the following:
const projectId ='ZZZZZZZZZZZZZZz';
const projectSecret='ZXXXZZXXXXXXXXXX';
const auth = 'Bearer ' + (projectId + ':' +projectSecret);
const ipfs = new IPFS({
host: 'ipfs.infura.io',
//host: 'nftpatent.infura-ipfs.io/',
port: 5001,
protocol: 'https',
headers: {
authorization: auth,
}
});
The issue is that i am unable to upload and post/pin to IPFS. My first thought is that I use the wrong host which should be the dedicated 'nftpatent.infura-ipfs.io' as this requires the auth but from what I have read research it seems everything stays the same and we need to provide auth only.
In my App.js, I have this to do the heavy lifting
// save document to IPFS,return its hash#, and set hash# to state
// https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add
//setState by setting ipfsImageHash to ipfsImageHash[0].hash
if (this.state.myToken.imageBuffer && this.state.myToken.imageBuffer.length > 0) {
await ipfs.add(this.state.myToken.imageBuffer, (err, ipfsHash) => {
console.log('IPFS hash: ' + ipfsHash + ', error: ' + err);
let myMetadata = JSON.parse(JSON.stringify(this.state.myToken.metadataBuffer));
myMetadata.image = this.state.web3ctx.ipfsGateway + ipfsHash[0].hash;
this.setState({
myToken: {
...this.state.myToken,
ipfsImageHash: ipfsHash[0].hash,
ipfsImageUrl: myMetadata.image,
metadataBuffer: myMetadata,
imageBuffer: ''
},
selectedTab: 'Metadata'
});
})
} else if (this.state.myToken.metadataBuffer && this.state.myToken.metadataBuffer.toString().length > 0) {
await ipfs.add(Buffer.from(JSON.stringify(this.state.myToken.metadataBuffer)), (err, ipfsHash) => {
console.log('IPFS hash: ' + ipfsHash + ', error: ' + err);
this.setState({
myToken: {
...this.state.myToken,
ipfsMetadataHash: ipfsHash[0].hash,
ipfsMetadataUrl: this.state.web3ctx.ipfsGateway + ipfsHash[0].hash
},
selectedTab: 'Metadata'
});
})
} else {
console.log('file could not be found: '
+ JSON.stringify(this.state.myToken.metadataBuffer, null, 2));
return 1;
}
};
`
And the error is
TypeError: Cannot read properties of undefined (reading '0')
Duplex.
src/App.js:287
myMetadata.image = this.state.web3ctx.ipfsGateway + ipfsHash[0].hash;
enter image description here
Please help as I can't seem to figure out the issues. ``
I tried working the auth and checking whether the host is correctly called. I believe the issue is with "auth" and not with scripts as they were working previously. Thanks in advance. `

Solana ECONNREFUSED error on localhost for the simple airdrop transaction

I launched my local solana environment with 'solana-test-validator' command, I have a simple POST API like this:
app.post('/test', async (_: any, res: any) => {
const connection = new Connection('http://localhost:8899', 'confirmed');
const wallet = Keypair.generate();
const airdropSignature = await connection.requestAirdrop(
wallet.publicKey,
LAMPORTS_PER_SOL
);
await connection.confirmTransaction(airdropSignature);
res.json({ message: 'Ok' });
});
And I'm getting an error "request to http://localhost:8899/ failed, reason: connect ECONNREFUSED".
Meanwhile my CLI works. What am I doing wrong?
MacOs, node version 18.0.6, #solana/web3.js version 1.55.0
I don't know why, but it worked for me after I changed 'localhost' to '127.0.0.1'

Coinbase-pro for Node.js - Websocket connection breaking with error: read ECONNRESET

I'm currently stuck with an issue I'm getting with the coinbase-pro-node npm package (https://github.com/coinbase/coinbase-pro-node). I'm connecting to the matches channel and listening for messages there but the connection with the Websocket breaks after a few hours without telling me much. I can't trace back the problem and it doesn't happen on the same intervals. Sometimes it breaks just minutes after I run the script. Thanks for the help.
The code:
const CoinbasePro = require('coinbase-pro');
var coinbaseWs = '';
function connect() {
coinbaseWs = new CoinbasePro.WebsocketClient(
['BTC-USD'],
'wss://ws-feed.pro.coinbase.com',
{
key: 'xxxx',
secret: 'xxxx',
passphrase: 'xxxx',
},
{ channels: ['matches'] }
);
coinbaseWs.on('message', async data => {
console.log(data)
});
coinbaseWs.on('error', err => {
console.error("Connection with Coinbase websocket failed with error: " + err);
console.log("Error stack trace: " + err.stack);
});
coinbaseWs.on('close', () => {
console.error("Connection with Coinbase websocket closed!");
});
}
connect();
Error stack:
Error: read ECONNRESET
File "internal/stream_base_commons.js", line 167, in TLSWrap.onStreamRead
it does break from time to time for no apparent reason. All you can do is listen for the heartbeat messages and use those to decide whether to re-initiate a new websocket feed. I raised a similar query directly with the coinbase pro/gdax customer support.

Failed to load resource: net::ERR_CONNECTION_REFUSED, socket io, redis

I am having problems starting the node server.js file because the port that it wants to use is taken by Laragon Apache which allows me to open the project in the browser.
This is the node server.js file :
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');
server.listen(8890);
io.on('connection', function (socket) {
console.log("client connected");
var redisClient = redis.createClient();
redisClient.subscribe('message');
redisClient.on("message", function(channel, data) {
console.log("mew message add in queue "+ data['message'] + " channel");
socket.emit(channel, data);
});
socket.on('disconnect', function() {
redisClient.quit();
});
});
When I start it in cmder with node server.js is can not use the port.Node server.js command in cmder:
client connected
events.js:160
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
D:\laragon\www\canvas-messenger\nodejs (master)
node server.js
With Laragon Apache on the browser console looks like this,
Failed to load resource: net::ERR_CONNECTION_REFUSED
and
GET http://localhost:8890/socket.io/?EIO=3&transport=polling&t=1524944736161-36 net::ERR_CONNECTION_REFUSED
error continuously repeting itself because the node server.js can not run I guess.
I have tried installing redis and socket io with laravel echo server, giving them different ports that would allow them to work with out making problems to each other but the functionality of the Chat in the browser would still be lost.
Thank you for reading !

Resources