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

safe gmtime, guard with mutex since not thread safe on non windows pl… #240

Merged
merged 6 commits into from
Jan 29, 2024

Conversation

hassanctech
Copy link
Contributor

@hassanctech hassanctech commented Jan 25, 2024

Issue #, if available: Address TSAN failures in Producer C

Description of changes:
C function gmtime is not threadsafe on non-windows platforms. Create a new GMTIME_SAFE macro which guards the gmtime call with a global mutex.

The if/def for this includes CYGWIN because I'm using pthread which our Thread platform dependent layer does not use for cygwin.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (8216b98) 80.35% compared to head (89ceb16) 80.31%.

❗ Current head 89ceb16 differs from pull request most recent head 9a63a34. Consider uploading reports for the commit 9a63a34 to get more accurate results

Files Patch % Lines
src/utils/src/Time.c 87.50% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #240      +/-   ##
===========================================
- Coverage    80.35%   80.31%   -0.05%     
===========================================
  Files           53       53              
  Lines        10798    10804       +6     
===========================================
  Hits          8677     8677              
- Misses        2121     2127       +6     

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

@hassanctech hassanctech marked this pull request as ready for review January 26, 2024 17:18
@hassanctech hassanctech merged commit 07dea9e into develop Jan 29, 2024
13 checks passed
@hassanctech hassanctech deleted the safe-gmtime branch January 29, 2024 22:47
hassanctech added a commit that referenced this pull request Mar 11, 2024
* Fix definition of LP64 for gcc

* Use INT64 instead of LL so the type is will consistent across platforms

* Modify threadpool teardown (#218)

* Modify threadpool teardown to avoid unlocking mutexes from a different thread than locked it.

* Remove an extra comma that made the format incorrect (#216)

* Use const PCHAR so C++ compilers won't complain about passing strings constants (#215)

* Add stream state machine iterator (#220)

* Define iterator function, add a Stream member var

* Replace recursive stepState calls with iterator

* Replace all Stream stepState calls with iterator

* Fix existing comment typos

* CLANG

* Rename 'keepIterating' member to be more clear

* Add null pointer checks to iterator

* CLANG

* Stylistic change based on precedent

* Remove redundant pStateMachine null check

* Remove another redundant null pointer check

* Fix null checks

* Add timerqueuekick and checkstatemachinetransition (#221)

* Add timerqueuekick and checkstatemachinetransition

* Increase sleep at end of threadpool test to give spawned threads time to free their memory

* Utils - Remove duplicate error code

* m1 build

* update cmake

* fix incompatible pointer error

* fix incompatible pointer error

* run tests

* cmake once

* no typecasting

* Revert "no typecasting"

This reverts commit f2096b8.

* Revert "Revert "no typecasting""

This reverts commit 7d53af0.

* everything working

* Add gcc-M1 CI test (#225)

* Add gcc M1 test

* testing

* more

* Update gcc path

* Try using LLP64 for Apple

* Add is null or empty

* Update CommonDefs.h (#229)

* Fix 32 bit crash issue (#230)

* fix 32-bit crash in threadpool and possible seg fault if get item was null

* clang format

* remove null item and keep iterating

* properly free threadpool if failed to create (#231)

* address compiler warnings, cleanup ci (#232)

* remove unnecessary double compiles, separate out test ci run into a separate section, address compile warning

* address multiple compile warnings

* address more compiler warnings for linux, separate out few more tests from build in ci

* move stuff around

* use consistent flags in pic library and test

* clang format

* only run test if flag FIXUP_ANNEX_B_TRAILING_NALU_ZERO is set, previously we re-built pic with this flag for the tests but the test itself segfaults if it's not set

* put tests behind ifdefs which require flags set

* tweak ci yml

* more ifdefing tests

* more ifdefs for tests

* more changes

* correct path for tsan/ubsan suppressions files

* address warning for linux implicit decl of pthread_getname_np

* define only once

* more ifdefs

* more ifdefs for tests

* ifdef more tests

* more ifdefs

* more ifdefs

* more ifdefs

* more ifdefs

* more ifdefs

* if thread count is going to overflow, return 0

* another if/def

* add build and testing with ALIGNED_MEMORY_MODEL and FIXUP_ANNEX_B_TRAILING_NALU_ZERO to test both paths in CI

* more ifdefs for unalign access

* more ifdefs for ubsan

* ifdef more tests for aligned memory model

* more memory aligned ifdefs for tests

* more if defs in tests

* make sure correct number of bytes for snprintf

* State machine name for logs (#233)

* Add state machine tag

* Add tag for client state machine

* Use char with fixed size

* Use default tags

* Random string

* Allow tag setting for state machines

* Add unit tests

* Free state machine

* Use createStateMachineWithTag instead

* Rename

* Address comments

* Silent (#234)

* Remove const in the api definition for getStateMachineName (#235)

* char*

* Remove const

* Enable tsan (#236)

* enable tsan

* lock access to global count to address tsan violation

* remove globals, use struct to thread

* some changes

* lock to protect data race in case of canceled thread still

* lock around terminate in tests for tsan data race

* free mutex in tests

* Release build (#237)

* Switch to ASSERT_EQ from assert to prevent release build optimization

* Fix assert

* Cleanup log statements

* Threadpool tsan (#238)

* Protect accessing threadpool with threaddata lock

* Fix potential seg fault from attempting to access queue after threadpool has been destroyed by locking the dataMutex around that queue, and having the destructor pass waiting tasks onto the queue when threads are stuck waiting for on said queue

* Fix typo from merge

* Reduce sleeps in threadpool

* Lock test utils mutex, and check for termination in actors before assigning pQueue

* need allocators set check

* wait on teardown of test threads

* removing accessing gTerminateCount in the for loop

* longer sleep to wait for threads to free their heap

* dramatically increase sleep

* Add sleep in the heap check in case it's still waiting for a thread to exit

* Infinite loop if memory isn't clear. Tests will timeout on GHA if the memory leak actually exists. If it's just waiting for threads to clean up, then it will keep waiting.

* Remove sleep from termination task

* Assert handle (#239)

* Use abort instead

* custom assert

* Fix definition

* Fix fprintf

* Simple assert

* Clang formatted

* Fix build issue

* safe gmtime, guard with mutex since not thread safe on non windows pl… (#240)

* safe gmtime, guard with mutex since not thread safe on non windows platforms

* clang format

* add cygwin to keep original gmtime since pthread isn't used there in our thread impl

* address pr comments, fix compile warnings in threadpool

* missed the extern variable name change

* add EXPECT_EQ around thread create and thread join calls in the unit tests, possibly address tsan complain where it it looks like multiple tests executing at the same time

* unlock stream mutex before acquiring the fom mutex to avoid deadlock with putframe (#242)

* Update ci.yml

using xcode 14.3.1 results in a linker issue with gcc, 15.1 fixes the issue, trying 15.2 since this appears to be the latest available.

* Update ci.yml

ci.yml formatting

* Reset current index in case it overflows out of range (#245)

* Add PR description lint (#248)

* Merge pull request #249 from awslabs/fix-read-windows

Fix readFile on Windows

---------

Co-authored-by: Dave Johansen <[email protected]>
Co-authored-by: jdelapla <[email protected]>
Co-authored-by: Stefan Kieszkowski <[email protected]>
Co-authored-by: Jeremy Gunawan <[email protected]>
Co-authored-by: Niyati Maheshwari <[email protected]>
Co-authored-by: Niyati Maheshwari <[email protected]>
Co-authored-by: Jeremy Gunawan <[email protected]>
Co-authored-by: Divya Sampath Kumar <[email protected]>
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.

3 participants