Skip to content

rpc: RPC over HTTP silently drops Infinity from results #780

Open

Description

@lionelhorn

Over RpcHttpClientAdapter, a non-finite number in a result is lost and the call still succeeds: a number property disappears and a number result becomes undefined. Over WebSocket the same calls return Infinity.

import { App } from '@deepkit/app';
import { ApplicationServer, FrameworkModule } from '@deepkit/framework';
import { rpc, RpcClient, RpcHttpClientAdapter } from '@deepkit/rpc';

interface Range {
    min: number;
    max: number;
}

@rpc.controller('range')
class RangeController {
    @rpc.action()
    unbounded(): Range {
        return { min: 0, max: Infinity };
    }

    @rpc.action()
    limit(): number {
        return -Infinity;
    }
}

const app = new App({ controllers: [RangeController], imports: [new FrameworkModule({ port: 8080, httpRpcBasePath: '/api' })] });
await app.get(ApplicationServer).start();

const range = new RpcClient(new RpcHttpClientAdapter('http://127.0.0.1:8080/api')).controller<RangeController>('range');
console.log(await range.unbounded().catch((error: Error) => error.message));
// actual: { min: 0 }, should be: { min: 0, max: Infinity } or an error
console.log(await range.limit().catch((error: Error) => error.message));
// actual: undefined, should be: -Infinity or an error

Master 0bb9fba, Node 26.13.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions