bun icon indicating copy to clipboard operation
bun copied to clipboard

Grpc EOF on 50kb+ response, as gRPC Server

Open allaboutstrategy opened this issue 2 months ago • 1 comments

What version of Bun is running?

1.1.3.3

What platform is your computer?

Linux Mint 22 x64

What steps can reproduce the bug?

I wanted to build a GRPC server with Bun. I worked all really good.

But when I tested an endpoint that sends a bit more data I noticed i get EOF on 50-60% of the requests the moment the size exeeds 50-60 kb.

on Nodejs it works flaweless even with 2mb.

anybody had such a problem before?

import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import {  type IPinnacleServiceServer } from '../../generated2/index_grpc_pb';
import * as grpcReflection from '@grpc/reflection';
import { PinnacleServiceService } from '../../generated2/index_grpc_pb';
import { Sport, SportsResponse } from '../../generated2/sports_pb';
import { createSportsHandler } from './handlers/sportsHandler';
import type { SportsCache } from '../services/Caches/sportsCache';
import { createPeriodsHandler } from './handlers/periodsHandler';
import type { PeriodsCache } from '../services/Caches/periodsCache';

// Pfad zur .proto-Datei

// Setze das gRPC-Logging
grpc.setLogger({
  log: (message) => console.log(`gRPC LOG: ${message}`),
  warn: (message) => console.warn(`gRPC WARN: ${message}`),
  error: (message) => console.error(`gRPC ERROR: ${message}`),
  debug: (message) => console.debug(`gRPC DEBUG: ${message}`),
});
//const PROTO_PATH = '../proto/sports';
const PROTO_PATH = Bun.resolveSync("../proto/index.proto", import.meta.dir);
// Lade die Proto-Datei
const packageDefinition = protoLoader.loadSync([PROTO_PATH], {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
});

// Server erstellen und starten
export function startServer(sportsCache: SportsCache,periodsCache:PeriodsCache) {
  const server = new grpc.Server();
  const handlers = {
    ...createSportsHandler(sportsCache),
    ...createPeriodsHandler(periodsCache)
  };
  server.addService(PinnacleServiceService,handlers);

  // const periodHandlers = createPeriodsHandler(periodsCache);
  // server.addService(PinnacleServiceService, periodHandlers);
  //server.addService(PinnacleServiceService, { getSports, getSportById });

  const reflection = new grpcReflection.ReflectionService(packageDefinition);
  reflection.addToServer(server);
  const port = '0.0.0.0:50051';
  server.bindAsync(port, grpc.ServerCredentials.createInsecure(), (err, bindPort) => {
    if (err) {
      console.error('Server start failed:', err);
    } else {
      console.log(`Server running at ${bindPort}`);
      //server.start();
    }
  });
}
...

this is my server btw.
tested it with grpcurl and a golang client same result.

Data are static so not changing

### What is the expected behavior?

Just the data^.

only work on 30-40% if i use 50-150kb + 

          "spreadShortDescription": "SPD",
          "moneylineShortDescription": "ML",
          "totalShortDescription": "POINTS",
          "team1TotalShortDescription": "POINTS",
          "team2TotalShortDescription": "POINTS"
        }
      ]
    }
  ]
}

Response trailers received:
(empty)
Sent 1 request and received 1 response

real    0m0.078s
user    0m0.014s
sys     0m0.042s


### What do you see instead?

time grpcurl -plaintext -d '{}' -proto ./index.proto -v localhost:50051 pinnacle.PinnacleService/GetAllPeriods

Resolved method descriptor:
rpc GetAllPeriods ( .common.Empty ) returns ( .sports.SportPeriodsResponse );

Request metadata to send:
(empty)

Response headers received:
content-type: application/grpc+proto
date: Sun, 15 Dec 2024 21:05:58 GMT
grpc-accept-encoding: identity,deflate,gzip

Response trailers received:
(empty)
Sent 1 request and received 0 responses
ERROR:
  Code: Internal
  Message: unexpected EOF

real    0m0.023s
user    0m0.000s
sys     0m0.012s


### Additional information

I changed it to run on Nodejs 22.12 then and there the whole project runs flawless, even with 2-3 megabyte of data.

allaboutstrategy avatar Dec 15 '24 21:12 allaboutstrategy