Problem/Motivation

The RegistrationCreationService is a stateful object which stores data internally. Since the service is not declared as a non-shared service, it is leaking its state to any code that retrieves the service from the container.

Steps to reproduce

// Run some code that sets an event instance on the service (e.g. `EventInstanceCapacity::render()`).
// ...

// Now in some later running code retrieve the service.
$service = \Drupal::service('recurring_events_registration.creation_service')
// We should have a clean instance of the service, but the data from the previous code is still present.
assert(empty($service->getEventInstance()), 'No data is leaked between uses of the service');

Proposed resolution

Mark the service as non-shared.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Issue summary: View changes

pfrenssen’s picture

Added a failing test that showcases the problem:

https://git.drupalcode.org/issue/recurring_events-3452632/-/jobs/1783093

There was 1 failure:
1) Drupal\Tests\recurring_events_registration\Kernel\RegistrationCreationServiceTest::testServiceInstantiation
A newly instantiated service should not have an event series.
Failed asserting that an object is empty.
pfrenssen’s picture

Status: Active » Needs review

Defining the service as non-shared solves the problem. The test passes now: https://git.drupalcode.org/issue/recurring_events-3452632/-/jobs/1783235

The other test failures are not related to this issue, ref. #3452641: Failing tests on main branch

owenbush’s picture

Thanks for this I'll get this merged.

  • owenbush committed 3224fa10 on 2.0.x authored by pfrenssen
    Issue #3452632 by pfrenssen: Registration creation service leaks data
    
owenbush’s picture

Status: Needs review » Fixed

This has been merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.