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

Refactor connection management #328

Merged
merged 17 commits into from
Sep 20, 2024
Merged

Conversation

mint-dewit
Copy link
Contributor

@mint-dewit mint-dewit commented May 3, 2024

Type of Contribution

This is a Code improvement

Current Behavior

Library consumers must keep track of how devices are created and initialised and are responsible for managing this. In addition, a device may not finish initialising until the first connection has been made.

Proposed Behavior

A Connection is an instance of an Integration Implementation (previously known as devices, this terminology proved to be a bit confusing as "TSR devices" connected to actual devices). TSR shall be responsible for creating and initialising the connections based upon a config provided by the library user. An integration must ensure to not get stuck during the initialisation.

Discussion

I think there may actually some use for devices not being initialised immediately as it prevents the timeline states from being sent into the integration when it isn't ready yet. At the same time, integrations should handle this "disconnected" state gracefully. Perhaps some additional life cycle hooks are required (i.e. to rediff the state from empty)

Status

This PR is part investigation and part implementation. Feedback is welcome at this time.

@mint-dewit mint-dewit changed the title chore: wip Refactor connection management May 3, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 3, 2024

Codecov Report

Attention: Patch coverage is 61.58537% with 126 lines in your changes missing coverage. Please review.

Project coverage is 57.15%. Comparing base (29ad13d) to head (3d5ee7e).
Report is 11 commits behind head on release52.

Files with missing lines Patch % Lines
...ne-state-resolver/src/service/ConnectionManager.ts 76.65% 53 Missing ⚠️
packages/timeline-state-resolver/src/conductor.ts 40.62% 19 Missing ⚠️
...-state-resolver/src/integrations/casparCG/index.ts 0.00% 11 Missing ⚠️
...imeline-state-resolver/src/service/stateHandler.ts 0.00% 11 Missing ⚠️
...eline-state-resolver/src/integrations/osc/index.ts 11.11% 8 Missing ⚠️
...e-state-resolver/src/integrations/sisyfos/index.ts 0.00% 6 Missing ⚠️
...e-state-resolver/src/integrations/quantel/index.ts 37.50% 5 Missing ⚠️
...ne-state-resolver/src/integrations/vizMSE/index.ts 0.00% 5 Missing ⚠️
...line-state-resolver/src/integrations/vmix/index.ts 0.00% 2 Missing ⚠️
...eline-state-resolver/src/service/DeviceInstance.ts 0.00% 2 Missing ⚠️
... and 4 more
Additional details and impacted files
@@              Coverage Diff              @@
##           release52     #328      +/-   ##
=============================================
+ Coverage      56.74%   57.15%   +0.40%     
=============================================
  Files            130      131       +1     
  Lines          10104    10400     +296     
  Branches        2386     2553     +167     
=============================================
+ Hits            5734     5944     +210     
- Misses          4368     4454      +86     
  Partials           2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Julusian Julusian left a comment

Choose a reason for hiding this comment

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

There are still a bunch of todos that need resolving, but I like the approach taken here and don't have any major problems with it.

I haven't read changes made to devices, but I suspect that some care will be needed in them. I know that some of them are doing assertions on when properties are defined, as they get defined by init, but now that init resolves immediately, will those assumptions still be correct?

id: string,
container: BaseRemoteDeviceIntegration<DeviceOptionsAnyInternal>
) {
const deviceOptions = this._config.get(id)
Copy link
Member

Choose a reason for hiding this comment

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

deviceOptions could be a parameter, which would avoid needing this guard which might want to throw.

This could actually be a race condition, if setConnections is called to remove a device between the start of createConnection and here, then the config could disappear.
So maybe this guard is a good thing, and should be documented as such? or it should continue as normal, with it following the normal destroy route soon after

// trigger device init
this._handleConnectionInitialisation(id, container).catch(() => {
this.emit('error', 'Device ' + id + ' failed to initialise')
this._connections.delete(id) // todo - this will cause device to be recreated next, which may cause a spiral?
Copy link
Member

Choose a reason for hiding this comment

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

Is more cleanup needed?
This is discarding the thread, but the thread is probably still running at this point?

@@ -172,7 +167,7 @@ export class Conductor extends EventEmitter<ConductorEvents> {

private _options: ConductorOptions

private devices = new Map<string, BaseRemoteDeviceIntegration<DeviceOptionsBase<any>>>()
public readonly connectionManager = new ConnectionManager()
Copy link
Member

Choose a reason for hiding this comment

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

should this be public, or should select methods be re-exposed on this conductor?

@mint-dewit mint-dewit force-pushed the feat/connection-mgmt-SOFIE-1152 branch from 7d9379c to a7ae873 Compare September 6, 2024 07:11
@mint-dewit mint-dewit changed the base branch from release51 to release52 September 6, 2024 09:13
@mint-dewit mint-dewit marked this pull request as ready for review September 11, 2024 14:08
@mint-dewit mint-dewit requested a review from a team as a code owner September 11, 2024 14:08
@mint-dewit
Copy link
Contributor Author

This is pretty much ready and I'm leaving this in state I'm happy with but the unit tests appear to be very inconsistent for reasons that elude me so that will require some attention

@nytamin nytamin merged commit d182f1f into release52 Sep 20, 2024
36 checks passed
@nytamin nytamin deleted the feat/connection-mgmt-SOFIE-1152 branch September 20, 2024 07:55
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.

4 participants