-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Expected Behavior
The client should connect to the sidecar without any error, like this:
{
message: '[HTTPClient, HTTPClient] Sidecar Started',
level: 'info',
timestamp: '2024-11-25T21:37:55.579Z'
}
{
message: 'DAPR audit-service client has been initialized successfully',
level: 'info',
timestamp: '2024-11-25T21:37:55.579Z'
}
{
message: '[HTTPServer, HTTPServerImpl] [Topic = store-audit] Registered Subscription with routes: default',
level: 'info',
timestamp: '2024-11-25T21:37:56.849Z'
}
{
message: '[HTTPServer, HTTPServer] Listening on 3010',
level: 'info',
timestamp: '2024-11-25T21:37:56.855Z'
}
{
message: '[HTTPServer, HTTPServer] Registering 1 PubSub Subscriptions',
level: 'info',
timestamp: '2024-11-25T21:37:56.856Z'
}
{
message: '[HTTPClient, HTTPClient] Sidecar Started',
level: 'info',
timestamp: '2024-11-25T21:37:56.861Z'
}
{
message: 'Dapr server started on host 127.0.0.1 and port 3010',
level: 'info',
timestamp: '2024-11-25T21:37:56.862Z'
}
{
message: '{"method":"GET","url":"/dapr/config","headers":{"host":"127.0.0.1:3010","user-agent":"Go-http-client/1.1","content-type":"application/json","dapr-app-id":"audit-service","accept-encoding":"gzip"},"statusCode":404,"responseTime":"5ms"}',
level: 'info',
timestamp: '2024-11-25T21:37:56.894Z'
}
{
message: '[HTTPServer, HTTPServer] Registered 1 PubSub Subscriptions',
level: 'info',
timestamp: '2024-11-25T21:37:56.905Z'
}
{
message: '{"method":"GET","url":"/dapr/subscribe","headers":{"host":"127.0.0.1:3010","user-agent":"Go-http-client/1.1","content-type":"application/json","accept-encoding":"gzip"},"statusCode":200,"responseTime":"5ms"}',
level: 'info',
timestamp: '2024-11-25T21:37:56.906Z'
}
This is the workaround I have found. I think its trying to connect 2 times to the sidecar, one time with the port I have provided and another one with the default port. I suppose thats why we are seeing [HTTPClient, HTTPClient] Sidecar Started
twice
Actual Behavior
So, actually I'm trying to use another port other than 3500
as the --dapr-http-port
port, the port a dapr client can use to connect to the sidecar. But it's not working, it seems like it tries to connect to the default port 3500
whether I precise a port or not.
Dapr sidecar command
dapr run --app-id audit-service \
--scheduler-host-address "63.250.53.226:50006" \
--app-port 3010 \
--dapr-http-port 3510 \
--dapr-http-max-request-size 4 \
--dapr-http-read-buffer-size 4 \
--enable-api-logging
...
res =>
INFO[0002] HTTP API Called app_id=audit-service code=204 duration=1 instance=Flyer-4.local method="PUT /v1.0/metadata/cliPID" scope=dapr.runtime.http-info size=0 type=log useragent=Go-http-client/1.1 ver=1.14.4
✅ You're up and running! Dapr logs will appear here.
The error I'm getting
{
message: '[HTTPClient, HTTPClient] Sidecar Started',
level: 'info',
timestamp: '2024-11-20T09:25:59.723Z'
}
{
message: 'DAPR audit-service client has been initialized successfully', // this is the client. As you can see it has started
level: 'info',
timestamp: '2024-11-20T09:25:59.723Z'
}
{
message: '[HTTPClient, HTTPClient] Awaiting Sidecar to be Started', // and this is where it goes back to awaiting state
level: 'info',
timestamp: '2024-11-20T09:26:02.266Z'
}
{
message: 'Error during Dapr initialization: DAPR_SIDECAR_COULD_NOT_BE_STARTED', // finally it crashs
level: 'error',
timestamp: '2024-11-20T09:26:33.063Z'
}
/Users/filymohamedsakine/Documents/secretstartups/audit/server.js:78
throw new Error(error);
^
Error: Error: DAPR_SIDECAR_COULD_NOT_BE_STARTED
at bootstrap (/Users/filymohamedsakine/Documents/secretstartups/audit/server.js:78:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.17.0
First time, it connects well to the sidecar on the right port then it tries with the default port 3500
. I have found a workaround to fix this supposed
bug. What I have found is to edit the default port in the package Settings.defaultHttpPort = "3500";
and it works.
I also tried to put the port in the host and comment the port like this
this.client = new DaprClient({
daprHost: `${this.host}:${this.sideCardPort}`,
// daprPort: this.sideCardPort,
daprApiToken: daprApiToken,
communicationProtocol: CommunicationProtocolEnum.HTTP,
maxBodySizeMb: 10,
logger: {
level: LogLevel.Debug,
service: new DaprLoggerWrapper(),
},
});
It worked for 1d and stopped working the next day (Dunno why it was working though). The workaround is still working, I even tried it today. This is the error I'm getting with host and port combined
{
message: 'Invalid address: 127.0.0.1:3510:3500',
level: 'error',
timestamp: '2024-11-25T14:44:57.400Z'
}
See the 3500
? As I said, I think no matter what the port we give to the client, it will try to connect to the default port.
Steps to Reproduce the Problem
Run a sidecar on any port other than 3500
and try to connect a dapr client to it
Sidecar command
dapr run --app-id app-service \
--app-port 3010 \
--dapr-http-port 3510 \
--dapr-http-max-request-size 4 \
--dapr-http-read-buffer-size 4 \
--enable-api-logging
Client code
class DaprClientWrapper {
constructor(appid, host, sideCardPort) {
this.appid = appid;
this.host = host;
this.sideCardPort = sideCardPort;
}
async init() {
this.client = new DaprClient({
daprHost: this.host,
daprPort: this.sideCardPort,
daprApiToken: process.env.DAPR_API_TOKEN,
communicationProtocol: CommunicationProtocolEnum.HTTP,
maxBodySizeMb: 10,
logger: {
level: LogLevel.Debug,
service: new DaprLoggerWrapper(),
},
});
}
async start() {
try {
await this.client.start();
if (this.client.getIsInitialized()) {
logger.info(
`DAPR ${this.appid} client has been initialized successfully`
);
} else {
logger.error(`DAPR ${this.appid} initialization failed`);
}
} catch (error) {
logger.error(error.toString());
}
}
async stop() {
try {
await this.client.stop();
logger.info("Dapr client has been stopped successfully");
} catch (error) {
logger.error(`DAPR client ${this.appid} stopping failed`);
}
}
}