Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger] Allow to close the transport connection#59862

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

andrew-demb
Copy link
Contributor

@andrew-dembandrew-demb commentedFeb 26, 2025
edited
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#53543
LicenseMIT

1. Implemented the possibility to make messenger transports resettable
2. Implemented reset Redis connection for Redis messenger transport

This feature may lead to decreased performance for messenger consumers (because connection will be resetted between processing messages).

One way to resolve it that I found - add configuration for resettable transports - aka "reset connection on kernel reset: true/false". For consumers it can be configured via env var to be "false", but for web "true".


UPD 2025-02-27: According to the feedback, I changed the implementation to another one to help with our use case.

Implemented a way to close messenger transport from the application, to allow free resources for long-running processes (like a long-running webserver)

@andrew-demb
Copy link
ContributorAuthor

Error: src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php:59:13: UndefinedClass: Class, interface or enum named Relay\Relay does not exist (seehttps://psalm.dev/019)
Error: src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php:740:34: UndefinedClass: Class, interface or enum named Relay\Relay does not exist (seehttps://psalm.dev/019)

I don't know how to handle this error. I didn't add Relay in the PR - probably an issue introduced by the Psalm update or existed before.

@andrew-demb
Copy link
ContributorAuthor

.................................zend_mm_heap corrupted
Job exited with: 134
Error: KO src/Symfony/Component/Validator

This CI failure for PHP 8.5 seems unrelated to PR

@HypeMC
Copy link
Member

At first glance, this looks like something that should be handled via a middleware, something likeDoctrineCloseConnectionMiddleware.

@andrew-demb
Copy link
ContributorAuthor

@HypeMC my use-case - a long-running webserver. Some of the requests triggersymfony/messenger-related code.

If such a request is handled - Redis connection is not closed until the webserver worker will be restarted.

@stof
Copy link
Member

is it an issue that the Redis connection is not closed ? When using a long-running webserver instead of PHP-FPM, isn't one of the goals being able to keep such connections instead of reconnecting all the time ?

andrew-demb reacted with eyes emoji

@andrew-demb
Copy link
ContributorAuthor

@stof As we're used (in our project) Redis for queues not so often, we're trying to avoid additional connections being opened to Redis with no reason (and other "cold" storages).

Just checked how Symfony behaves with Doctrine DBAL connections - they are not closed between requests either.

I'm OK with changing the PR implementation just to open the way to close connection (add method "close" to the Redis transport) - to allow close connection from the application code (using the event system).

What do you think about this?@stof@HypeMC

@ro0NL
Copy link
Contributor

doctrine can be optionally closed at the middelware layer:https://github.com/symfony/symfony/blob/7.3/src/Symfony/Bridge/Doctrine/Messenger/DoctrineCloseConnectionMiddleware.php

im wondering if redis should follow a similar approach

@andrew-demb
Copy link
ContributorAuthor

I can introduce the interface "CloseableTransportInterface" that will allow closing used transport connections from the userland (in my case - from "kernel.terminate" event listener).

I can see, that this can be implemented by most transports (AMQP, Redis, Doctrine DBAL, etc)

@andrew-dembandrew-demb changed the title[Messenger] Reset Redis connection between requests[Messenger] Allow to close the messenger transport connectionFeb 27, 2025
@andrew-dembandrew-dembforce-pushed the53543-redis-messenger-reset branch from619bffb toedaf24aCompareFebruary 27, 2025 17:57
@andrew-demb
Copy link
ContributorAuthor

According to the feedback, I changed the implementation to another one to help with our use case.

Implemented a way to close messenger transport from the application, to allow free resources for long-running processes (like a long-running webserver)

@@ -80,6 +80,12 @@ public function reset(): void
$this->doMysqlCleanup = false;
}

public function close(): void
{
$this->driverConnection->close();
Copy link
Member

Choose a reason for hiding this comment

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

this transport does not own the DBAL connection, so it should not close it either

andrew-demb reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Updated. Other transports seem OK to me to be closeable (they remain their own connection or already have some "reset" methods).

Copy link
Contributor

@ro0NLro0NLFeb 27, 2025
edited
Loading

Choose a reason for hiding this comment

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

@stof from a messenger:consume POV i think doctrine transport is "closeable"

that's what DoctrineCloseConnectionMiddleware does no?

i tend to believe we should either solve it at the transport layer or the middleware layer in an agnostic matter IMHO

Copy link
Member

Choose a reason for hiding this comment

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

DoctrineCloseConnectionMiddleware is closing the connectionif you enable that middleware.

the transport itself should not close the connection implicitly, because it is not owning the connection (the connection might be used for multiple purposes)

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

Can you add a note in the CHANGELOG file about the new interface?

@andrew-demb
Copy link
ContributorAuthor

status:needs review

@OskarStarkOskarStark changed the title[Messenger] Allow to close the messenger transport connection[Messenger] Allow to close the transport connectionMar 4, 2025
@fabpotfabpotforce-pushed the53543-redis-messenger-reset branch from28f85d4 to9788aeeCompareMarch 5, 2025 08:11
@fabpot
Copy link
Member

Thank you@andrew-demb.

andrew-demb reacted with heart emoji

@fabpotfabpot merged commit89bae9c intosymfony:7.3Mar 5, 2025
8 checks passed
@fabpotfabpot mentioned this pull requestMay 2, 2025
@andrew-dembandrew-demb deleted the 53543-redis-messenger-reset branchMay 10, 2025 17:07
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof left review comments

@ro0NLro0NLro0NL left review comments

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

Disconnect Redis connection for symfony/redis-messenger on "kernel.reset"
6 participants
@andrew-demb@HypeMC@stof@ro0NL@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp