Skip to content

Segmentation Fault / Memory Dump when returning JSON objects from Fastify routes #125

@MehmetAliPolat1515

Description

@MehmetAliPolat1515

When using Perry to compile a simple Fastify server, returning a JavaScript object from a route handler causes the server to silently crash or dump memory. The client (curl) receives a massive string of zeros and random numbers (e.g., 0.0000...4243991582), and the server process drops.
When observing the logs, the Perry runtime fails at [json_value_to_jsvalue] and attempts to look up undefined fields (like email), eventually failing to parse the JSON.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple Fastify server.
  2. Create a POST route that returns a standard JS object.
import Fastify from "fastify";

const server = Fastify({ logger: true });

server.post('/gonderi-yap', async (request, reply) => {
  // Returning an object causes the crash
  return { status: "Success", message: "Data received" }; 
});

server.listen({ port: 3000, host: '0.0.0.0' });
  1. Compile with perry compile src/sunucu.ts -o server
  2. Send a POST request via curl:
    curl -X POST http://localhost:3000/gonderi-yap -d "Test"
    Expected behavior
    The server should return a valid JSON response: {"status": "Success", "message": "Data received"}.
    Actual behavior
    The client receives a memory dump string (0.00000...2121995791). The server logs output the following before dropping:
[req_json] body present: true
[req_json] body = Test
[req_json] JSON parse failed
[json_value_to_jsvalue] Building object with 1 fields
[json_value_to_jsvalue] Post-build 'email' lookup: bits=0x7FFC000000000001 is_string=false is_undefined=true

Workaround
If the route returns a primitive string instead of an object, Perry handles it perfectly without crashing:

// This works perfectly
return "ISLEM_BASARILI: Data received\n";

Conclusion
While the project is promising, the inability to safely return and serialize JSON objects—resulting in memory leaks and pointer errors—shows that Perry is not yet production-ready. I have decided to stop using it for my current project due to these instability issues, but I am leaving this issue here to help the team debug the runtime JSON parser.

AI: Content is generated by artificial intelligence, proactively verify the authenticity and accuracy.

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