Skip to content

mobile: Replace std::thread with Envoy::Thread::PosixThread#32610

Merged
abeyad merged 15 commits intoenvoyproxy:mainfrom
fredyw:posix_thread
Mar 6, 2024
Merged

mobile: Replace std::thread with Envoy::Thread::PosixThread#32610
abeyad merged 15 commits intoenvoyproxy:mainfrom
fredyw:posix_thread

Conversation

@fredyw
Copy link
Copy Markdown
Member

@fredyw fredyw commented Feb 27, 2024

This PR replaces the use of std::thread with Envoy::Thread::PosixThread (backed by pthread). The reason for this change is because std::thread may throw an exception and when exceptions are disabled, it will crash the program. For some certain code, such as the cert validation, it should not crash the program when a thread cannot be created, but it should return an error instead.

This PR also refactors the POSIX thread wrapper implementation and exposes the APIs via Envoy::Thread::PosixThreadFactory and Envoy::Thread::PosixThread so that they can be used directly by Envoy Mobile since Envoy Mobile only supports Android and iOS and those OSes support POSIX. The Envoy::Thread::PosixThread has additional functions not available in Envoy::Thread::Thread, such as pthreadId() and joinable() to make the migration from std::thread to Envoy::Thread::PosixThread easier. The Envoy::PosixThread::pthreadId() is especially useful for doing a comparison with Envoy::PosixThreadFactory::currentPthreadId().

Risk Level: medium
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: mobile

@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #32610 was opened by fredyw.

see: more, trace.

@fredyw fredyw force-pushed the posix_thread branch 9 times, most recently from 2c7068d to 4e56de8 Compare February 28, 2024 02:19
@fredyw
Copy link
Copy Markdown
Member Author

fredyw commented Feb 28, 2024

/retest

@fredyw fredyw marked this pull request as ready for review February 28, 2024 03:25
@fredyw
Copy link
Copy Markdown
Member Author

fredyw commented Feb 28, 2024

/assign @abeyad @alyssawilk

Copy link
Copy Markdown
Contributor

@abeyad abeyad left a comment

Choose a reason for hiding this comment

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

this is awesome, thanks @fredyw !

@abeyad
Copy link
Copy Markdown
Contributor

abeyad commented Feb 28, 2024

adding @danzh2010 since she wrote the original code (I think), in case she has any concerns

@danzh2010
Copy link
Copy Markdown
Contributor

Similarly, we can't use Envoy::Thread::Thread because, it doesn't have a way to check for the successful or failure status of the thread creation.

The Envoy::Thread::PosixThread wrapper has similar APIs with std::thread, such as PosixThread::threadId() and PosixThread::joinable() to make the migration from std::thread to Envoy::Thread::PosixThread easier.

Can you elaborate it? Envoy::Thread::Thread is just an interface and I assume PosixThread is an implementation of it.

fredyw added 5 commits March 1, 2024 01:56
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
fredyw added 3 commits March 2, 2024 16:03
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
@fredyw
Copy link
Copy Markdown
Member Author

fredyw commented Mar 2, 2024

This PR is ready for another review. PTAL.

Copy link
Copy Markdown
Contributor

@abeyad abeyad left a comment

Choose a reason for hiding this comment

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

awesome, thanks @fredyw !

Signed-off-by: Fredy Wijaya <fredyw@google.com>
abeyad
abeyad previously approved these changes Mar 4, 2024
Signed-off-by: Fredy Wijaya <fredyw@google.com>
fredyw added 2 commits March 5, 2024 15:32
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
@fredyw
Copy link
Copy Markdown
Member Author

fredyw commented Mar 5, 2024

/retest

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Two thoughts for now - mostly trusting Ali on E-M changes
/wait

Signed-off-by: Fredy Wijaya <fredyw@google.com>
fredyw added 2 commits March 5, 2024 18:15
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Envoy changes LGTM.

Copy link
Copy Markdown
Contributor

@abeyad abeyad left a comment

Choose a reason for hiding this comment

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

/lgtm mobile

@repokitteh-read-only
Copy link
Copy Markdown

no relevant owners for "mobile"

🐱

Caused by: a #32610 (review) was submitted by @abeyad.

see: more, trace.

@abeyad
Copy link
Copy Markdown
Contributor

abeyad commented Mar 5, 2024

added @lizan for cross company review

@abeyad abeyad unassigned lizan Mar 6, 2024
@abeyad
Copy link
Copy Markdown
Contributor

abeyad commented Mar 6, 2024

added @lizan for cross company review

Actually, per the new policy, this doesn't need cross company review: https://github.com/envoyproxy/envoy/pull/30995/files

So I'm merging

@abeyad abeyad merged commit 4af5231 into envoyproxy:main Mar 6, 2024
@fredyw fredyw deleted the posix_thread branch March 6, 2024 15:51
mattjo added a commit to mattjo/envoy that referenced this pull request Mar 6, 2024
* origin: (34 commits)
  update CODEOWNER (envoyproxy#32457)
  Delete unused runtime flag. (envoyproxy#32739)
  mobile: Use direct ByteBuffer to pass data between C++ and Java (envoyproxy#32715)
  quic: support cert selection by SNI, non-PEM formats (envoyproxy#32260)
  mobile: Replace std::thread with Envoy::Thread::PosixThread (envoyproxy#32610)
  grpc: Add support for max frame length in gPRC frame decoding (envoyproxy#32511)
  build(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 (envoyproxy#32728)
  build(deps): bump the examples-golang-network group in /examples/golang-network/simple with 1 update (envoyproxy#32732)
  build(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 in /contrib/golang/filters/http/test/test_data/property (envoyproxy#32731)
  build(deps): bump otel/opentelemetry-collector from `246dfe9` to `71ac13c` in /examples/opentelemetry (envoyproxy#32730)
  build(deps): bump the examples-grpc-bridge group in /examples/grpc-bridge/server with 2 updates (envoyproxy#32720)
  build(deps): bump the contrib-golang group in /contrib/golang/router/cluster_specifier/test/test_data/simple with 1 update (envoyproxy#32721)
  build(deps): bump the contrib-golang group in /contrib/golang/filters/http/test/test_data/echo with 1 update (envoyproxy#32722)
  build(deps): bump the examples-ext-authz group in /examples/ext_authz/auth/grpc-service with 1 update (envoyproxy#32723)
  build(deps): bump the contrib-golang group in /contrib/golang/filters/http/test/test_data/routeconfig with 1 update (envoyproxy#32724)
  build(deps): bump the examples-load-reporting group in /examples/load-reporting-service with 1 update (envoyproxy#32726)
  build(deps): bump the contrib-golang group in /contrib/golang/filters/http/test/test_data/buffer with 1 update (envoyproxy#32727)
  build(deps): bump the examples-golang-http group in /examples/golang-http/simple with 1 update (envoyproxy#32729)
  opentelemetrytracer: Add User-Agent header to OTLP trace exporters (envoyproxy#32659)
  build: remove incorrect cc_library after tls code move (envoyproxy#32714)
  ...
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.

5 participants