nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.48k stars 1.47k forks source link

memory allocation error after raised Exception and catched in 2.0.2? #23312

Closed itsumura-h closed 7 months ago

itsumura-h commented 7 months ago

Description

I'm creating relatively large web application in Nim. I found a SIGSEGV: Illegal storage access. error happen after only raised Exception and catched safety. I tried to create simple example but it seems only for relatively large program. And it not happen when using Nim v2.0.0. Only in 2.0.2.

reproduction scenario

  1. Clone application from github

    git clone https://github.com/itsumura-h/realworld-basolato-htmx
  2. Run docker container. 8000 port on host need to be free.

    cd realworld-basolato-htmx
    git switch alloc-error
    docker compose build
    docker compose up -d
    docker compose exec app bash
    cd /root/project/src
    choosenim 2.0.2
  3. install dependency packages

    nimble install -y -d
  4. create .env file copy .env.eample to .env DB Connection section should be as bellow

DB_DATABASE="database" # sqlite file path or database name
DB_USER="user"
DB_PASSWORD="pass"
DB_HOST="postgres"  # host ip address
DB_PORT=5432 # postgres default...5432, mysql default...3306
DB_MAX_CONNECTION=10 # should be smaller than (DB max connection / running num processes)
DB_TIMEOUT=30 # secounds
  1. run migration and seed for database

    ./resetDb.sh
  2. run application

    ducere serve
  3. access browser http://localhost:8000/

  4. sign in http://localhost:8000/sign-in

    email: test@example.com
    password: password
  5. access setting page http://localhost:8000/settings click Update Settings button without filing password

  6. In the top of the screen, you can see error messages as expect スクリーンショット 2024-02-17 01-59-51

  7. Click the left top icon to go top page, but it not moved. If you check the terminal, you can see the error message like this スクリーンショット 2024-02-17 02-03-44

My speculation

In the No.10, this error is raised src/app/models/aggregates/user/vo/password.nim as DomainError and catched in update proc insrc/app/http/controllers/htmx_setting_controller.nim スクリーンショット 2024-02-17 02-09-43 スクリーンショット 2024-02-17 02-09-59

However, after catched error and responde safety, something memory management seems to be broken and Illegal storage access error happen in the next time access.

Nim Version

Nim Compiler Version 2.0.2 [Linux: amd64] Compiled at 2023-12-15 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: c4c44d10df8a14204a75c34e499def200589cb7c

Current Output

No response

Expected Output

not happen SIGSEGV error.

Possible Solution

No response

Additional Information

No response

itsumura-h commented 7 months ago

In devel branch, it is fixed

Nim Compiler Version 2.1.1 [Linux: amd64] Compiled at 2024-02-16 Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 92c8c6d5f4e5a96b71bf4eca5f6a136410f97d6e