Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix goroutine leaking #103

Merged
merged 12 commits into from
Feb 15, 2024
Merged

Fix goroutine leaking #103

merged 12 commits into from
Feb 15, 2024

Conversation

maranqz
Copy link
Member

@maranqz maranqz commented Jan 26, 2024

A goroutine leak occurs when the TRM is used in crons or worker, and the main context lives for a long time.

To solve this problem before PR, you can set setttings.Cancelable equals true.

2. fixed problems for sql and sqlx
@maranqz maranqz changed the base branch from main to v1 January 26, 2024 06:40
@maranqz maranqz changed the title Fix goroutine leaking [WIP] Fix goroutine leaking Jan 26, 2024
@maranqz maranqz marked this pull request as draft January 26, 2024 06:41
2. fixed data race with sqlmock
2. Added Closed for transaction to catch when transaction really closed.
3. Fix gorm goroutine leak
2. Fixed linters error
@maranqz maranqz changed the title [WIP] Fix goroutine leaking Fix goroutine leaking Feb 4, 2024
@maranqz maranqz marked this pull request as ready for review February 4, 2024 10:25
gorm/factory.go Outdated Show resolved Hide resolved
redis/transaction.go Outdated Show resolved Hide resolved
@@ -77,7 +88,7 @@ func (t *Transaction) Commit(ctx context.Context) error {
return nil
}

defer t.deactivate()
defer t.isClosed.Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что будет, если будет ошибка при релизе сейвпоинта?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEGIN;

SAVEPOINT SP1;

SAVEPOINT SP2;

RELEASE SAVEPOINT SP2; -- return err

ROLLBACK TO SAVEPOINT SP1; -- т.к. будет вверх возвращаться err
-- Если err перехватят, то RELEASE SAVEPOINT SP1 в случае если ошибка и не закрылся коннект.

ROLLBACK; -- т.к. будет вверх возвращаться err и не закрылся коннект
-- Если err перехватят, то успешный COMMIT и не закрылся коннект.

Чуть более правильным был бы подход, когда мы создаем отдельный объект на вложенную транзакцию, однако я не готов делать это в текущем PR, но для V2 можно сделать.

Copy link

@Foxprodev Foxprodev Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот я как раз про закрытый коннект, сейчас кажется не отслеживается, если коннект закроется.

Так-то ПР хуже не делает точно, просто набрасываю какие еще есть кейсы, в которых может остаться горутина

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обсудили в ЛС, вопросов нет

@maranqz maranqz merged commit f57a4ba into v1 Feb 15, 2024
11 checks passed
@maranqz maranqz deleted the v1-fix-goroutine-leak branch February 15, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants