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

SIGSEGV fix test #1867

Open
wants to merge 8 commits into
base: tracker-12.x.x
Choose a base branch
from
Open

SIGSEGV fix test #1867

wants to merge 8 commits into from

Conversation

nick-delirium
Copy link
Contributor

@nick-delirium nick-delirium commented Jan 29, 2024

Test: moving everything except batchWriter out of webworker thread

Crash log data indicating Worker Scope + Fetch attempt

Magic signature

blink::FetchManager::Loader::Start

Stack Trace

Thread 16 DedicatedWorker thread (id: 0x008b431d)crashedMAGIC SIGNATURE THREAD
0x000000012970b684(Google Chrome Framework -fetch_manager.cc:647)blink::FetchManager::Loader::Start()
0x000000012970ab24(Google Chrome Framework -fetch_manager.cc:1268)blink::FetchManager::Fetch(blink::ScriptState*, blink::FetchRequestData*, blink::AbortSignal*, blink::ExceptionState&)
0x000000012fda61ac(Google Chrome Framework -global_fetch.cc:85)??blink::(anonymous namespace)::GlobalFetchImplblink::WorkerGlobalScope::Fetch(blink::ScriptState*, blink::V8UnionRequestOrUSVString const*, blink::RequestInit const*, blink::ExceptionState&)
0x000000013003f534(Google Chrome Framework -v8_worker_global_scope.cc:836)blink::(anonymous namespace)::v8_worker_global_scope::FetchOperationCallback(v8::FunctionCallbackInfov8::Value const&)
0x0000000177e4fc30
0x0000000177e4fc30
0x0000000177e4d6a4
0x0000000177e4d6a4
0x000000017011b554
0x0000000177e4b144
0x0000000177e4ae34
0x0000000127a5fdf0(Google Chrome Framework -simulator.h:178)v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)
0x0000000127a5fdf0(Google Chrome Framework -execution.cc:529)v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handlev8::internal::Object, v8::internal::Handlev8::internal::Object, int, v8::internal::Handlev8::internal::Object)
0x0000000128032eb8(Google Chrome Framework -api.cc:5459)v8::Function::Call(v8::Localv8::Context, v8::Localv8::Value, int, v8::Localv8::Value
)
0x0000000128031718(Google Chrome Framework -v8_script_runner.cc:787)blink::V8ScriptRunner::CallFunction(v8::Localv8::Function, blink::ExecutionContext*, v8::Localv8::Value, int, v8::Localv8::Value, v8::Isolate)
0x0000000127e5e7e8(Google Chrome Framework -v8_event_handler_non_null.cc:170)blink::V8EventHandlerNonNull::InvokeWithoutRunnabilityCheck(blink::bindings::V8ValueOrScriptWrappableAdapter, blink::HeapVector<blink::ScriptValue, 0u> const&)
0x0000000127e5cc84(Google Chrome Framework -js_event_handler.cc:137)blink::JSEventHandler::InvokeInternal(blink::EventTarget&, blink::Event&, v8::Localv8::Value)
0x000000012a4748c4(Google Chrome Framework -js_based_event_listener.cc:155)blink::JSBasedEventListener::Invoke(blink::ExecutionContext*, blink::Event*)
0x0000000127d33e68(Google Chrome Framework -event_target.cc:922)blink::EventTarget::FireEventListeners(blink::Event&, blink::EventTargetData*, blink::HeapVector<cppgc::internal::BasicMember<blink::RegisteredEventListener, cppgc::internal::StrongMemberTag, cppgc::internal::DijkstraWriteBarrierPolicy, cppgc::internal::DisabledCheckingPolicy, cppgc::internal::CompressedPointer>, 1u>)
0x0000000127d33e68(Google Chrome Framework -event_target.cc:840)blink::EventTarget::FireEventListeners(blink::Event&)
0x0000000127d33e68(Google Chrome Framework -event_target.cc:922)blink::EventTarget::FireEventListeners(blink::Event&, blink::EventTargetData*, blink::HeapVector<cppgc::internal::BasicMember<blink::RegisteredEventListener, cppgc::internal::StrongMemberTag, cppgc::internal::DijkstraWriteBarrierPolicy, cppgc::internal::DisabledCheckingPolicy, cppgc::internal::CompressedPointer>, 1u>)
0x0000000127d33e68(Google Chrome Framework -event_target.cc:840)blink::EventTarget::FireEventListeners(blink::Event&)
0x000000012a391edc(Google Chrome Framework -event_target.cc:735)blink::EventTarget::DispatchEventInternal(blink::Event&)
0x000000012975749c(Google Chrome Framework -event_target.cc:728)blink::WorkerGlobalScope::ReceiveMessage(blink::BlinkTransferableMessage)
0x000000012ab8459c(Google Chrome Framework -bind_internal.h:713)void base::internal::FunctorTraits<void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), void>::Invoke<void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), blink::DedicatedWorkerObjectProxy*, blink::BlinkTransferableMessage, blink::WorkerThread*>(void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), blink::DedicatedWorkerObjectProxy*&&, blink::BlinkTransferableMessage&&, blink::WorkerThread*&&)
0x000000012ab8459c(Google Chrome Framework -bind_internal.h:868)void base::internal::InvokeHelper<false, void, 0ul, 1ul, 2ul>::MakeItSo<void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), std::__Cr::tuple<WTF::CrossThreadUnretainedWrapperblink::DedicatedWorkerObjectProxy, blink::BlinkTransferableMessage, WTF::CrossThreadUnretainedWrapperblink::WorkerThread>>(void (blink::DedicatedWorkerObjectProxy::&&)(blink::BlinkTransferableMessage, blink::WorkerThread), std::__Cr::tuple<WTF::CrossThreadUnretainedWrapperblink::DedicatedWorkerObjectProxy, blink::BlinkTransferableMessage, WTF::CrossThreadUnretainedWrapperblink::WorkerThread>&&)
0x000000012ab8459c(Google Chrome Framework -bind_internal.h:968)void base::internal::Invoker<base::internal::BindState<void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), WTF::CrossThreadUnretainedWrapperblink::DedicatedWorkerObjectProxy, blink::BlinkTransferableMessage, WTF::CrossThreadUnretainedWrapperblink::WorkerThread>, void ()>::RunImpl<void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), std::__Cr::tuple<WTF::CrossThreadUnretainedWrapperblink::DedicatedWorkerObjectProxy, blink::BlinkTransferableMessage, WTF::CrossThreadUnretainedWrapperblink::WorkerThread>, 0ul, 1ul, 2ul>(void (blink::DedicatedWorkerObjectProxy::&&)(blink::BlinkTransferableMessage, blink::WorkerThread), std::__Cr::tuple<WTF::CrossThreadUnretainedWrapperblink::DedicatedWorkerObjectProxy, blink::BlinkTransferableMessage, WTF::CrossThreadUnretainedWrapperblink::WorkerThread>&&, std::__Cr::integer_sequence<unsigned long, 0ul, 1ul, 2ul>)
0x000000012ab8459c(Google Chrome Framework -bind_internal.h:919)base::internal::Invoker<base::internal::BindState<void (blink::DedicatedWorkerObjectProxy::)(blink::BlinkTransferableMessage, blink::WorkerThread), WTF::CrossThreadUnretainedWrapperblink::DedicatedWorkerObjectProxy, blink::BlinkTransferableMessage, WTF::CrossThreadUnretainedWrapperblink::WorkerThread>, void ()>::RunOnce(base::internal::BindStateBase*)
0x000000012aa0f3c4(Google Chrome Framework -callback.h:153)base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow*)
0x000000012aa0f3c4(Google Chrome Framework -thread_controller_with_message_pump_impl.cc:326)base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
0x000000012aa0f3c4(Google Chrome Framework -thread_controller_with_message_pump_impl.cc)non-virtual thunk to base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
0x000000012aa0f3c4(Google Chrome Framework -callback.h:153)base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow*)
0x000000012aa0f3c4(Google Chrome Framework -thread_controller_with_message_pump_impl.cc:326)base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
0x000000012aa0f3c4(Google Chrome Framework -thread_controller_with_message_pump_impl.cc)non-virtual thunk to base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
0x0000000127dd8440(Google Chrome Framework -message_pump_default.cc:40)base::MessagePumpDefault::Run(base::MessagePump::Delegate*)
0x0000000128d79b94(Google Chrome Framework -run_loop.cc)non-virtual thunk to base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta)
0x0000000128d79b94(Google Chrome Framework -run_loop.cc:134)base::RunLoop::Run(base::Location const&)
0x0000000128d78ff0(Google Chrome Framework -non_main_thread_impl.cc:182)blink::scheduler::NonMainThreadImpl::SimpleThreadImpl::Run()
0x0000000128b40a08(Google Chrome Framework -platform_thread_posix.cc:101)base::(anonymous namespace)::ThreadFunc(void*)
0x000000019e65bfa4(libsystem_pthread.dylib + 0x00006fa4)_pthread_start
0x000000019e65bfa4(libsystem_pthread.dylib + 0x00006fa4)_pthread_start

read: #1390

Summary by CodeRabbit

  • Refactor
    • Restructured types and interfaces for improved worker data communication.
    • Implemented a WebWorkerManager class to streamline interactions with Web Workers.
  • New Features
    • Introduced new types for precise control over worker operations and data handling.
  • Bug Fixes
    • Corrected import paths in unit tests to align with updated module locations.
  • Tests
    • Updated unit tests to accommodate changes in import paths and functionality.
  • Chores
    • Enhanced code cleanliness by removing redundant code segments.

Copy link

coderabbitai bot commented Jan 29, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent overhaul in the tracker's codebase focuses on enhancing web worker management and data handling. Key alterations include the redefinition of communication types between the main thread and workers, introduction of a WebWorkerManager for streamlined worker operations, and updates in test imports reflecting the new structure. This reorganization aims at improving efficiency, scalability, and maintainability of the tracker system.

Changes

Files Summary
.../src/common/interaction.ts Restructured worker data communication types, introduced new types like Batch, Restart, etc.
.../src/main/app/index.ts Refactored to use WebWorkerManager for Web Worker interactions, updated getTimezone return type.
.../src/main/app/workerManager/QueueSender.ts Simplified isCompressing initialization based on onCompress presence.
.../src/main/app/workerManager/index.ts Added WebWorkerManager class for managing Web Worker communication and operations.
.../src/tests/BatchWriter.unit.test.ts
.../src/tests/PrimitiveEncoder.unit.test.ts
.../src/tests/QueueSender.unit.test.ts
Updated import paths and minor adjustments in test setup.
.../src/webworker/index.ts Refactored message handling, removed QueueSender import, added updateStatus function.

"In the realm of code, where the bits do hop,

A rabbit worked, never willing to stop.

🎉 With changes anew, the tracker did leap,

🐾 On digital fields, its efficiency to keep."


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Attention: Patch coverage is 0.52356% with 190 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (tracker-12.x.x@dce890f). Click here to learn what that means.

❗ Current head 4ca87a7 differs from pull request most recent head 19f187c. Consider uploading reports for the commit 19f187c to get more accurate results

Files Patch % Lines
...racker/tracker/src/main/app/workerManager/index.ts 0.00% 100 Missing and 15 partials ⚠️
tracker/tracker/src/main/app/index.ts 0.00% 42 Missing and 6 partials ⚠️
tracker/tracker/src/webworker/index.ts 0.00% 19 Missing and 8 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             tracker-12.x.x    #1867   +/-   ##
=================================================
  Coverage                  ?   13.27%           
=================================================
  Files                     ?      178           
  Lines                     ?    12810           
  Branches                  ?     2729           
=================================================
  Hits                      ?     1701           
  Misses                    ?    10277           
  Partials                  ?      832           
Flag Coverage Δ
tracker 26.70% <0.52%> (?)
ui 3.07% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@nick-delirium
Copy link
Contributor Author

@coderabbitai review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 88ea925 and 271f53f.
Files ignored due to path filters (1)
  • tracker/tracker/package.json is excluded by: !**/*.json
Files selected for processing (8)
  • tracker/tracker/src/common/interaction.ts (1 hunks)
  • tracker/tracker/src/main/app/index.ts (21 hunks)
  • tracker/tracker/src/main/app/workerManager/QueueSender.ts (2 hunks)
  • tracker/tracker/src/main/app/workerManager/index.ts (1 hunks)
  • tracker/tracker/src/tests/BatchWriter.unit.test.ts (1 hunks)
  • tracker/tracker/src/tests/PrimitiveEncoder.unit.test.ts (1 hunks)
  • tracker/tracker/src/tests/QueueSender.unit.test.ts (2 hunks)
  • tracker/tracker/src/webworker/index.ts (4 hunks)
Additional comments: 22
tracker/tracker/src/common/interaction.ts (3)
  • 10-18: The addition of new types to ToWorkerData such as Stop, Batch, WorkerStart, BeaconSizeLimit, ToWriterData, ForceFlushBatch, CheckQueue, ResetWriter, and WriterFinalize significantly expands the range of messages that can be sent to worker threads. This change aligns with the PR's objective to restructure web worker thread handling for better stability and crash prevention.
  • 20-32: The FromWorkerData type has been expanded with new types like Restart, Failure, NotInit, Compress, QEmpty, Status, and BatchReady. This enhancement facilitates a more comprehensive communication protocol between the worker threads and the main thread, allowing for detailed status updates and error handling.
  • 34-60: Introduction of new types such as BeaconSizeLimit, ToWriterData, WorkerStart, and WorkerAuth within interaction.ts provides a clearer and more structured approach to handling data between the main thread and worker threads. This structured approach is crucial for maintaining the stability and efficiency of the web worker's operations, especially in light of the segmentation fault issue the PR aims to address.
tracker/tracker/src/tests/PrimitiveEncoder.unit.test.ts (1)
  • 2-2: The update of the import path for PrimitiveEncoder from './PrimitiveEncoder.js' to '../webworker/PrimitiveEncoder.js' reflects the restructuring of the project's directory and file organization. This change is necessary for the tests to correctly locate and use the PrimitiveEncoder module after its relocation.
tracker/tracker/src/tests/BatchWriter.unit.test.ts (1)
  • 1-1: The update of the import path for BatchWriter from './BatchWriter' to '../webworker/BatchWriter' indicates the module's relocation to a different directory. This change ensures that the unit tests for BatchWriter are aligned with the new project structure, facilitating proper module resolution and testing.
tracker/tracker/src/webworker/index.ts (2)
  • 4-4: The change from importing Type as MType to importing Message directly simplifies the import statement and aligns with the updated message handling strategy in the web worker. This change is part of the broader effort to streamline communication between the main thread and the worker thread.
  • 42-108: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [25-131]

The restructuring of message handling within the web worker, including the introduction of updateStatus function and the replacement of specific message types with more generalized ones (to_writer, beacon_size_limit, reset_writer), simplifies the worker's logic. This simplification is crucial for isolating the cause of the segmentation fault by reducing the complexity within the worker thread, aligning with the PR's objectives.

tracker/tracker/src/main/app/workerManager/QueueSender.ts (1)
  • 10-10: The removal of the isCompressing property initialization and its subsequent assignment based on the presence of the onCompress parameter in the constructor simplifies the QueueSender class. This change likely reflects a shift in how compression is handled, possibly moving the responsibility outside of QueueSender or making it a more explicit decision at the time of instantiation.
tracker/tracker/src/tests/QueueSender.unit.test.ts (2)
  • 2-2: The update of the import path for QueueSender to reflect its new location within the project structure ensures that the unit tests are correctly aligned with the source code. This change is necessary for maintaining the integrity of the test suite following the restructuring of the project's directory organization.
  • 13-13: Updating the baseURL constant in the QueueSender.unit.test.ts file without corresponding changes in the test logic suggests that this update is merely to align with changes elsewhere in the project, such as the server configuration or the environment setup. This change should not affect the functionality of the tests but ensures they remain relevant and accurate.
tracker/tracker/src/main/app/workerManager/index.ts (1)
  • 27-202: The introduction of the WebWorkerManager class encapsulates the management of web worker operations, including starting, stopping, resetting, and authorizing operations. This centralization is a significant improvement in managing worker threads, aligning with the PR's objectives to enhance stability by simplifying the web worker's responsibilities. The class methods provide a clear and structured approach to interacting with the worker thread, which is crucial for preventing crashes related to segmentation faults.
tracker/tracker/src/main/app/index.ts (11)
  • 38-40: The import of WebWorkerManager and related types from interaction.js is correctly implemented, aligning with the PR objectives to manage web worker operations more effectively.
  • 130-130: The modification of the getTimezone function to explicitly return a string is a good practice for ensuring type consistency.
  • 165-165: The introduction of the WebWorkerManager instance as a private readonly field in the App class is a significant change. It's crucial to ensure that all references to the old this.worker are updated to use this.workerManager to maintain functionality.
Verification successful

The script intended to search for references to this.worker in TypeScript files within the src/ directory failed due to the directory not being found. This suggests a potential issue with the script's execution context or a misunderstanding of the repository's structure. To accurately verify the original comment's concern, a revised approach to search the entire codebase without assuming the presence of a specific src/ directory is necessary. Let's attempt to search for references to this.worker again, this time without specifying a directory, to ensure we cover all possible locations within the repository.


The search results indicate that there are no remaining references to this.worker that should have been updated to this.workerManager within the context of the App class in tracker/tracker/src/main/app/index.ts. All references found are correctly using this.workerManager. Additionally, references to this.worker in tracker/tracker/src/main/app/workerManager/index.ts are appropriate as they pertain to the internal workings of the WebWorkerManager class itself, where this.worker likely refers to a Web Worker instance managed by the WebWorkerManager.

Therefore, the original review comment's concern has been addressed properly in the codebase, and there are no issues regarding the update from this.worker to this.workerManager within the App class.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to `this.worker` which should be replaced with `this.workerManager`.
rg --type ts "this.worker" src/

Length of output: 76



Script:

#!/bin/bash
# Search for any remaining references to `this.worker` which should be replaced with `this.workerManager`, without assuming the presence of a specific src/ directory.
rg --type ts "this.worker"

Length of output: 2821

* 247-253: Creating a new `Worker` instance and passing it to the `WebWorkerManager` constructor is a critical change. Ensure that the `WEBWORKER_BODY` blob contains the correct worker code and that error handling is implemented for worker initialization failures. * 313-345: The `handleWorkerMsg` method's implementation for handling messages from the worker is comprehensive. However, ensure that all new message types (`restart`, `not_init`, `failure`, `compress`, `queue_empty`) are correctly handled in the worker's message processing logic. * 347-347: The `_debug` method's implementation for error reporting is appropriate. However, ensure that the `__debug_report_edp` endpoint is correctly configured and can handle the error reporting format. * 814-814: The call to `this.workerManager?.processMessage` with the `start` type in `uploadOfflineRecording` method is crucial for initializing the worker with session start parameters. Ensure that the worker's `onmessage` handler correctly processes the `start` message type. * 852-853: The call to `this.workerManager?.authorizeWorker` in `uploadOfflineRecording` method is essential for authorizing the worker with the session token and beacon size limit. Ensure that the worker correctly handles the authorization logic. * 914-914: The call to `this.workerManager?.startWorker` in the `_start` method is critical for starting the worker with the necessary session parameters. It's important to ensure that the worker's `onmessage` handler is set up to correctly process the `start` message type. * 1025-1025: The call to `this.workerManager?.authorizeWorker` in the `_start` method is crucial for authorizing the worker with the new session token and beacon size limit. Ensure that the worker's authorization logic is correctly implemented to handle these parameters. * 1232-1233: The call to `this.workerManager?.stopWorker` in the `stop` method is important for correctly stopping the worker when the tracking is stopped. Ensure that the worker's termination logic is correctly implemented.

@nick-delirium nick-delirium changed the title SIGSEV fix test SIGSEGV fix test Feb 9, 2024
@nick-delirium nick-delirium marked this pull request as ready for review February 19, 2024 12:50
@nick-delirium nick-delirium changed the base branch from dev to tracker-12.x.x February 19, 2024 12:50
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5ca1923 and 4ca87a7.
Files ignored due to path filters (1)
  • tracker/tracker/package.json is excluded by: !**/*.json
Files selected for processing (8)
  • tracker/tracker/src/common/interaction.ts (1 hunks)
  • tracker/tracker/src/main/app/index.ts (21 hunks)
  • tracker/tracker/src/main/app/workerManager/QueueSender.ts (2 hunks)
  • tracker/tracker/src/main/app/workerManager/index.ts (1 hunks)
  • tracker/tracker/src/tests/BatchWriter.unit.test.ts (1 hunks)
  • tracker/tracker/src/tests/PrimitiveEncoder.unit.test.ts (1 hunks)
  • tracker/tracker/src/tests/QueueSender.unit.test.ts (2 hunks)
  • tracker/tracker/src/webworker/index.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • tracker/tracker/src/main/app/workerManager/QueueSender.ts
Additional comments: 27
tracker/tracker/src/common/interaction.ts (5)
  • 10-18: The type definitions for ToWorkerData are clear and well-structured, covering a wide range of worker operations. Ensure that all these types are used in the worker message handling logic to maintain type safety and clarity.
  • 20-20: The FromWorkerData type is comprehensive, covering various responses from the worker. It's important to ensure that the worker's message handling logic correctly interprets these types to facilitate clear communication between the main thread and the worker.
  • 22-41: The detailed type definitions for messages from and to the worker (BatchReady, Status, Compress, etc.) are well-defined, promoting type safety and clarity in worker communication. It's crucial that the implementation of these message types in the worker and the main thread aligns with these definitions.
  • 49-56: The WorkerStart type is well-structured, providing clear information required to start a worker. Including Options as part of this type allows for flexible configuration. Ensure that the worker initialization logic properly utilizes these options.
  • 58-60: The WorkerAuth type definition is concise and relevant, especially for authentication purposes. It's important to ensure that the worker's authentication logic correctly handles the token and beaconSizeLimit fields.
tracker/tracker/src/tests/PrimitiveEncoder.unit.test.ts (2)
  • 2-2: The update to the import path for PrimitiveEncoder reflects a structural change in the codebase. Ensure that this new path is correct and that the PrimitiveEncoder functionality remains unaffected by its new location.
  • 4-4: The tests for PrimitiveEncoder cover various scenarios, including initial state, handling of different data types, and buffer overflow conditions. It's important to ensure these tests are comprehensive and reflect the encoder's expected behavior in the new structure.
tracker/tracker/src/tests/BatchWriter.unit.test.ts (2)
  • 1-1: The update to the import path for BatchWriter reflects a structural change in the codebase. Ensure that this new path is correct and that the BatchWriter functionality remains unaffected by its new location.
  • 3-3: The tests for BatchWriter cover various aspects of its functionality, including initialization, message writing, and batch finalization. It's important to ensure these tests are comprehensive and accurately reflect the BatchWriter's behavior in the new structure.
tracker/tracker/src/webworker/index.ts (6)
  • 4-4: The change in the import statement from Type to Message aligns with the refactoring effort to simplify and clarify message handling between the worker and the main thread. Ensure that the Message import is correctly utilized throughout the worker's logic.
  • 25-28: The introduction of the updateStatus function is a good practice for managing and communicating the worker's status. Ensure that this function is called appropriately to reflect the worker's state accurately.
  • 46-53: The logic for resetting the writer and handling the worker's status update is clear and follows best practices for managing worker states. Ensure that these operations are correctly sequenced to avoid potential race conditions or state inconsistencies.
  • 71-95: The updated message handling logic, especially for writer_finalize, reset_writer, and forceFlushBatch, simplifies the worker's responsibilities. Ensure that these message types are correctly processed and that their handling aligns with the worker's intended behavior.
  • 113-132: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [105-125]

The handling for beacon_size_limit messages is crucial for managing data transmission limits. Ensure that the logic for setting the beacon size limit is correctly implemented and that it interacts properly with the BatchWriter's functionality.

  • 129-131: The logic for handling restart messages is important for the worker's ability to recover from errors or changes in conditions. Ensure that the initiateRestart function is correctly implemented and called in appropriate scenarios.
tracker/tracker/src/tests/QueueSender.unit.test.ts (3)
  • 2-2: The update to the import path for QueueSender reflects a structural change in the codebase. Ensure that this new path is correct and that the QueueSender functionality remains unaffected by its new location.
  • 13-13: The update to the baseURL value from 'MYBASEURL' to 'BASEURL' in the tests for QueueSender should be verified to ensure it aligns with the intended testing environment and does not affect the test outcomes.
Verification successful

The verification process has confirmed that the update to the baseURL value from 'MYBASEURL' to 'BASEURL' in the QueueSender.unit.test.ts file is isolated to this specific test and does not conflict with any other configurations or setups within the project. There is no evidence of 'MYBASEURL' being used elsewhere in the project, suggesting that the change is unlikely to have unintended effects on the testing environment or outcomes. Therefore, the update should be aligned with the intended testing environment and not adversely affect the test outcomes.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if 'BASEURL' is correctly configured in the environment or test setup
echo "Ensure 'BASEURL' is correctly set for testing purposes."

Length of output: 126



Script:

#!/bin/bash
# Search for occurrences of 'BASEURL' and 'MYBASEURL' within the project to understand its context and usage.
echo "Searching for 'BASEURL' occurrences..."
rg 'BASEURL'
echo "Searching for 'MYBASEURL' occurrences..."
rg 'MYBASEURL'

Length of output: 294


Script:

#!/bin/bash
# Identify and review configuration files or test setup scripts for 'BASEURL' definition or usage.
echo "Identifying configuration or setup scripts..."
fd --type f --exec grep -H 'BASEURL' {}

Length of output: 221

* 15-15: The tests for `QueueSender` cover various scenarios, including authorization, compression, and error handling. It's important to ensure these tests are comprehensive and accurately reflect the `QueueSender`'s behavior in the new structure.
tracker/tracker/src/main/app/workerManager/index.ts (1)
  • 27-202: The WebWorkerManager class is well-structured and provides a centralized way to manage worker operations. Ensure that all methods (finalize, reset, initiateRestart, etc.) are correctly implemented and that the worker's lifecycle is managed efficiently. Pay special attention to error handling and state management to prevent potential issues.
tracker/tracker/src/main/app/index.ts (8)
  • 38-40: The introduction of WebWorkerManager and related types from ../../common/interaction.js is a significant change aimed at centralizing worker management. Ensure that the WebWorkerManager class and the FromWorkerData type are implemented correctly and efficiently handle worker interactions.
  • 130-130: The explicit return type of string for the getTimezone function is a good practice for clarity and type safety. This change enhances code readability and maintainability.
  • 247-253: Creating a new worker instance and initializing WebWorkerManager with it is a crucial part of the changes. However, ensure that the WEBWORKER_BODY blob contains the correct worker code and that error handling is robust enough to manage worker initialization failures gracefully.
  • 347-347: The _debug method is used for error reporting and debugging. Ensure that the error logging mechanism is consistent across the application and that sensitive information is not inadvertently logged.
  • 403-408: The _nCommit method's use of requestIdleCb to defer message processing is a good practice for performance optimization. However, ensure that the conditions under which messages are added and processed are correct and that there are no potential race conditions or data integrity issues.
  • 814-814: The uploadOfflineRecording method's logic for starting the worker and uploading the session buffer is critical. Ensure that the session data is correctly prepared and that the worker is properly authorized and configured before uploading. Additionally, verify that error handling and retry logic are robust.
  • 882-882: The _start method's logic for starting a new session and handling cold starts is complex. Ensure that the session initialization logic is correct, especially regarding session token handling, worker authorization, and session metadata assignment. Also, verify that the conditions under which a new session is started are correctly implemented.
  • 1232-1233: Stopping the worker in the stop method is a critical operation. Ensure that the worker is stopped gracefully and that all necessary cleanup operations are performed to prevent memory leaks or other issues.

Comment on lines +313 to +345
handleWorkerMsg(data: FromWorkerData) {
if (data.type === 'restart') {
this.stop(false)
void this.start({}, true)
} else if (data.type === 'not_init') {
this.debug.warn('OR WebWorker: writer not initialised; restarting worker')
} else if (data.type === 'failure') {
this.stop(false)
this.debug.error('worker_failed', data.reason)
this._debug('worker_failed', data.reason)
} else if (data.type === 'compress') {
const batch = data.batch
const batchSize = batch.byteLength
if (batchSize > this.compressionThreshold) {
gzip(data.batch, { mtime: 0 }, (err, result) => {
if (err) {
this.debug.error('Openreplay compression error:', err)
this.stop(false)
if (this.restartAttempts < 3) {
this.restartAttempts += 1
void this.start({}, true)
}
} else {
this.workerManager?.sendCompressedBatch(result)
}
})
} else {
this.workerManager?.sendUncompressedBatch(batch)
}
} else if (data.type === 'queue_empty') {
this.onSessionSent()
}
}
Copy link

Choose a reason for hiding this comment

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

The handleWorkerMsg method has been significantly updated to handle various worker messages, including 'restart', 'not_init', 'failure', 'compress', and 'queue_empty'. It's important to ensure that each case is handled correctly, especially the compression logic and error handling. Additionally, consider the performance implications of the compression operation and whether it could block the main thread.

- gzip(data.batch, { mtime: 0 }, (err, result) => {
+ gzip(data.batch, { mtime: 0 }, async (err, result) => {

Consider making the gzip operation asynchronous to avoid blocking the main thread.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
handleWorkerMsg(data: FromWorkerData) {
if (data.type === 'restart') {
this.stop(false)
void this.start({}, true)
} else if (data.type === 'not_init') {
this.debug.warn('OR WebWorker: writer not initialised; restarting worker')
} else if (data.type === 'failure') {
this.stop(false)
this.debug.error('worker_failed', data.reason)
this._debug('worker_failed', data.reason)
} else if (data.type === 'compress') {
const batch = data.batch
const batchSize = batch.byteLength
if (batchSize > this.compressionThreshold) {
gzip(data.batch, { mtime: 0 }, (err, result) => {
if (err) {
this.debug.error('Openreplay compression error:', err)
this.stop(false)
if (this.restartAttempts < 3) {
this.restartAttempts += 1
void this.start({}, true)
}
} else {
this.workerManager?.sendCompressedBatch(result)
}
})
} else {
this.workerManager?.sendUncompressedBatch(batch)
}
} else if (data.type === 'queue_empty') {
this.onSessionSent()
}
}
handleWorkerMsg(data: FromWorkerData) {
if (data.type === 'restart') {
this.stop(false)
void this.start({}, true)
} else if (data.type === 'not_init') {
this.debug.warn('OR WebWorker: writer not initialised; restarting worker')
} else if (data.type === 'failure') {
this.stop(false)
this.debug.error('worker_failed', data.reason)
this._debug('worker_failed', data.reason)
} else if (data.type === 'compress') {
const batch = data.batch
const batchSize = batch.byteLength
if (batchSize > this.compressionThreshold) {
gzip(data.batch, { mtime: 0 }, async (err, result) => {
if (err) {
this.debug.error('Openreplay compression error:', err)
this.stop(false)
if (this.restartAttempts < 3) {
this.restartAttempts += 1
void this.start({}, true)
}
} else {
this.workerManager?.sendCompressedBatch(result)
}
})
} else {
this.workerManager?.sendUncompressedBatch(batch)
}
} else if (data.type === 'queue_empty') {
this.onSessionSent()
}
}

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.

None yet

1 participant