samp-node icon indicating copy to clipboard operation
samp-node copied to clipboard

typeorm, sequlize getting stuck block terminal execute

Open dockfries opened this issue 7 months ago • 0 comments

"use strict";

require("reflect-metadata");
const typeorm = require("typeorm");

const AppDataSource = new typeorm.DataSource({
  type: "mysql",
  host: "localhost",
  port: 3306,
  username: "root",
  password: "",
  database: "omp",
  synchronize: false,
  logging: false,
  entities: [],
  subscribers: [],
  migrations: [],
});

// block terminal execute, but keydown enter will continue console.log, not 100% trigger, but maybe 90%
AppDataSource.initialize()
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  });

Perhaps this repository is no longer under maintenance, but this issue should be noted for friends who want to try developing samp-node in the future.

Currently, for some mainstream orm frameworks, the fatal problem is blocking execution.

Every time it runs, it is possible to block execution. It is not 100% triggered, but it is very frequent. Switching on and off the omp server multiple times will encounter it.

I encountered it in a Windows environment and did not test Linux. I have tried both node versions 16 and 20, and I used my self-developed infernus starter template+open.mp server.

https://github.com/dockfries/samp-node-block-issue

You can download release directly to reproduce.

The trigger condition for this issue is not related to async, regardless of whether you place it in setTimeout/process. nextTick/Prompt.

The situation of terminal blocking is similar to when we use Windows and swipe the mouse over the terminal, waiting for the user to press enter before continuing.

After running the server, I encountered this blocking situation and had to manually press enter to resolve it before executing the output result of console.log in the above code

Sometimes blocking makes the server appear to be shut down, meaning that the samp client cannot ping. Sometimes it can ping, but the player will be in a connected. joining the game state. In short, it is blocked and must press enter to get everything back to normal.

So I have temporarily suspended development.

I hope to one day solve the fatal blocking problem.

Related issues, #6 #15 #24

encounter a block

When you encounter a blockage, the output result of your terminal is as follows. Only output when you press enter or Ctrl+c to end

[2023-12-02T22:57:30+0800] [Info] Loading plugin: samp-node
[02/12/2023 - 22:57:30] -> [INFO]: plugin is using samp-node.json config file
// console.log not executed
[2023-12-02T22:57:31+0800] [Info] Legacy Network started on port 7777

Not encountering block


[2023-12-02T22:57:31+0800] [Info] Legacy Network started on port 7777
<ref *1> DataSource {
  '@instanceof': Symbol(DataSource),
  migrations: [],
// ......................
  metadataTableName: 'typeorm_metadata',
  queryResultCache: undefined,
  relationLoader: RelationLoader { connection: [Circular *1] },
  relationIdLoader: RelationIdLoader {
    connection: [Circular *1],
    queryRunner: undefined
  },
  isInitialized: true
}
[2023-12-02T22:58:38+0800] [Info] Failed to announce legacy network to open.mp list

alternative solutions

such as axios requests and games api on the samp-node side, and a 64-bit node server to provide http services and database operations, such as using the nest.js framework.

But I don't know the performance gap between a 32-bit node application going to the local http request service calling the database and the 32-bit node application calling orm directly to get the data.

However, if you use nest.js to write services, you can even write another front-end application, such as vue/react, and then adjust the same set of http interfaces for both the game server and the front-end client users.

dockfries avatar Dec 02 '23 14:12 dockfries