mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
logging
This commit is contained in:
@@ -234,7 +234,7 @@ export class StratumV1Client {
|
|||||||
eStratumErrorCode.OtherUnknown,
|
eStratumErrorCode.OtherUnknown,
|
||||||
'Authorization validation error',
|
'Authorization validation error',
|
||||||
errors).response();
|
errors).response();
|
||||||
console.log(err);
|
//console.log(err);
|
||||||
const success = await this.write(err);
|
const success = await this.write(err);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ import { StratumV1JobsService } from './stratum-v1-jobs.service';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class StratumV1Service implements OnModuleInit {
|
export class StratumV1Service implements OnModuleInit {
|
||||||
|
|
||||||
|
private socketTimeout = 0;
|
||||||
|
private emptySocket = 0;
|
||||||
|
private normalClosure = 0;
|
||||||
|
private errorClosure = 0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly bitcoinRpcService: BitcoinRpcService,
|
private readonly bitcoinRpcService: BitcoinRpcService,
|
||||||
private readonly clientService: ClientService,
|
private readonly clientService: ClientService,
|
||||||
@@ -61,7 +66,11 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
const cleanup = async (reason: string) => {
|
const cleanup = async (reason: string) => {
|
||||||
if (client.extraNonceAndSessionId != null) {
|
if (client.extraNonceAndSessionId != null) {
|
||||||
await client.destroy();
|
await client.destroy();
|
||||||
console.log(`Client ${client.extraNonceAndSessionId} disconnected, Reason: ${reason}`);
|
if(reason == 'Error'){
|
||||||
|
this.errorClosure++;
|
||||||
|
}else{
|
||||||
|
this.normalClosure++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!socket.destroyed) {
|
if (!socket.destroyed) {
|
||||||
socket.end();
|
socket.end();
|
||||||
@@ -76,16 +85,22 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
// Handle socket timeouts
|
// Handle socket timeouts
|
||||||
socket.on('timeout', async () => {
|
socket.on('timeout', async () => {
|
||||||
console.log(`Socket timeout ${socket.remoteAddress}, ${socket.bytesRead}/${socket.bytesWritten}, ${client.clientSubscription?.userAgent}`);
|
if(socket.bytesRead == 0 || socket.bytesWritten == 0){
|
||||||
|
this.emptySocket++;
|
||||||
|
}else{
|
||||||
|
this.socketTimeout++;
|
||||||
|
}
|
||||||
await cleanup("Timeout");
|
await cleanup("Timeout");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle errors properly
|
// Handle errors properly
|
||||||
socket.on('error', async (error: Error) => {
|
socket.on('error', async (error: Error) => {
|
||||||
console.log(`Socket error: ${error.message}`);
|
|
||||||
await cleanup("Error");
|
await cleanup("Error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ensure server itself handles errors
|
// Ensure server itself handles errors
|
||||||
@@ -96,6 +111,14 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`Stratum server is listening on port ${port}`);
|
console.log(`Stratum server is listening on port ${port}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
console.log(`Socket stats: ${this.emptySocket} empty, ${this.socketTimeout} timeouts, ${this.normalClosure} normal closure, ${this.errorClosure} error closure`);
|
||||||
|
this.emptySocket = 0;
|
||||||
|
this.socketTimeout = 0;
|
||||||
|
this.normalClosure = 0;
|
||||||
|
this.errorClosure = 0;
|
||||||
|
}, 1000 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user