René's URL Explorer Experiment


Title: [BUG] Data races · Issue #329 · etr/libhttpserver · GitHub

Open Graph Title: [BUG] Data races · Issue #329 · etr/libhttpserver

X Title: [BUG] Data races · Issue #329 · etr/libhttpserver

Description: Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues Description The documentation states that All functio...

Open Graph Description: Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues Description T...

X Description: Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues D...

Opengraph URL: https://github.com/etr/libhttpserver/issues/329

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Data races","articleBody":"### Prerequisites\r\n\r\n* [X] Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=\u0026q=repo%3Aetr%2Flibhttpserver\u0026type=Issues\r\n\r\n### Description\r\n\r\nThe documentation states that `All functions are guaranteed to be completely reentrant and thread-safe (unless differently specified)`. However, the `webserver` implementation does not use any protection while reading/modifying its member variables (`registered_resources`, `registered_resources_str`, `bans` and `allowances`).\r\n\r\n### Steps to Reproduce\r\n\r\nHere is a small test that show the issue when compiled using clang-16 with thread sanitizing enabled:\r\n```cpp\r\n\r\nLT_BEGIN_AUTO_TEST(basic_suite, thread_safety)\r\n    simple_resource resource;\r\n\r\n    std::atomic_bool done = false;\r\n    auto register_thread = std::thread([\u0026]() {\r\n        int i = 0;\r\n        using namespace std::chrono;\r\n        while (!done) {\r\n            ws-\u003eregister_resource(\r\n                    std::string(\"/route\") + std::to_string(++i), \u0026resource);\r\n        }\r\n    });\r\n\r\n    auto get_thread = std::thread([\u0026](){\r\n        while (!done) {\r\n            CURL *curl = curl_easy_init();\r\n            std::string s;\r\n            std::string url = \"localhost:\" PORT_STRING \"/route\" + std::to_string(\r\n                                            (int)((rand() * 10000000.0) / RAND_MAX));\r\n            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());\r\n            curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);\r\n            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);\r\n            curl_easy_setopt(curl, CURLOPT_WRITEDATA, \u0026s);\r\n            curl_easy_perform(curl);\r\n            curl_easy_cleanup(curl);\r\n        }\r\n    });\r\n\r\n    using namespace std::chrono_literals;\r\n    std::this_thread::sleep_for(10s);\r\n    done = true;\r\n    if (register_thread.joinable()) {\r\n        register_thread.join();\r\n    }\r\n    if (get_thread.joinable()) {\r\n        get_thread.join();\r\n    }\r\n    LT_CHECK_EQ(1, 1);\r\nLT_END_AUTO_TEST(thread_safety)\r\n```\r\n\r\n**Expected behavior:** \r\n\r\nNo data races are detected by clang.\r\n\r\n**Actual behavior:**\r\nClang reports the following data race (and others):\r\n\r\n```txt\r\nRunning test (1): thread_safety\r\n==================\r\nWARNING: ThreadSanitizer: data race (pid=21795)\r\n  Read of size 8 at 0x7b1400003550 by thread T1:\r\n    #0 memcmp /clang-16.0.1/projects/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:939:3 (lt-basic+0x67439)\r\n    #1 memcmp /clang-16.0.1/projects/compiler-rt/lib/tsan/rtl/../../sanitizer_common/sanitizer_common_interceptors.inc:935:1 (lt-basic+0x67439)\r\n    #2 httpserver::webserver::finalize_answer(MHD_Connection*, httpserver::details::modded_request*, char const*) \u003cnull\u003e (libhttpserver.so.0+0x227b2)\r\n    #3 MHD_connection_handle_idle \u003cnull\u003e (libmicrohttpd.so.12+0xd1ab) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #4 call_handlers daemon.c (libmicrohttpd.so.12+0x118af) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #5 MHD_epoll daemon.c (libmicrohttpd.so.12+0x194ad) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #6 MHD_polling_thread daemon.c (libmicrohttpd.so.12+0x1a02e) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #7 named_thread_starter mhd_threads.c (libmicrohttpd.so.12+0x24515) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n\r\n  Previous write of size 8 at 0x7b1400003550 by thread T2:\r\n    #0 operator new(unsigned long) /clang-16.0.1/projects/compiler-rt/lib/tsan/rtl/tsan_new_delete.cpp:64:3 (lt-basic+0xea6e5)\r\n    #1 std::pair\u003cstd::_Rb_tree_iterator\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e\u003e, bool\u003e std::_Rb_tree\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e, std::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e, std::_Select1st\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e\u003e, std::less\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e\u003e, std::allocator\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e\u003e\u003e::_M_emplace_unique\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e, httpserver::http_resource*\u003e\u003e(std::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e, httpserver::http_resource*\u003e\u0026\u0026) \u003cnull\u003e (libhttpserver.so.0+0x2669a)\r\n\r\n  Location is heap block of size 72 at 0x7b1400003520 allocated by thread T2:\r\n    #0 operator new(unsigned long) /clang-16.0.1/projects/compiler-rt/lib/tsan/rtl/tsan_new_delete.cpp:64:3 (lt-basic+0xea6e5)\r\n    #1 std::pair\u003cstd::_Rb_tree_iterator\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e\u003e, bool\u003e std::_Rb_tree\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e, std::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e, std::_Select1st\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e\u003e, std::less\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e\u003e, std::allocator\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e const, httpserver::http_resource*\u003e\u003e\u003e::_M_emplace_unique\u003cstd::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e, httpserver::http_resource*\u003e\u003e(std::pair\u003cstd::__cxx11::basic_string\u003cchar, std::char_traits\u003cchar\u003e, std::allocator\u003cchar\u003e\u003e, httpserver::http_resource*\u003e\u0026\u0026) \u003cnull\u003e (libhttpserver.so.0+0x2669a)\r\n\r\n  Thread T1 'MHD-single' (tid=21814, running) created by main thread at:\r\n    #0 pthread_create /clang-16.0.1/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1048:3 (lt-basic+0x2db2f)\r\n    #1 MHD_create_thread_ \u003cnull\u003e (libmicrohttpd.so.12+0x2443d) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #2 MHD_create_named_thread_ \u003cnull\u003e (libmicrohttpd.so.12+0x24602) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #3 MHD_start_daemon_va \u003cnull\u003e (libmicrohttpd.so.12+0x1e4de) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #4 MHD_start_daemon \u003cnull\u003e (libmicrohttpd.so.12+0x1a1d6) (BuildId: 72677d816e65dce550957833f9aea14ac2e0e4c8)\r\n    #5 httpserver::webserver::start(bool) \u003cnull\u003e (libhttpserver.so.0+0x20090)\r\n\r\n  Thread T2 (tid=21815, running) created by main thread at:\r\n    #0 pthread_create /clang-16.0.1/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1048:3 (lt-basic+0x2db2f)\r\n    #1 std::thread::_M_start_thread(std::unique_ptr\u003cstd::thread::_State, std::default_delete\u003cstd::thread::_State\u003e\u003e, void (*)()) \u003cnull\u003e (libstdc++.so.6+0xed8f9) (BuildId: 06e9553aa6e15b32e77410de83bbdd7d208a620d)\r\n\r\nSUMMARY: ThreadSanitizer: data race (/home/florian/work/libhttpserver/build/src/.libs/libhttpserver.so.0+0x227b2) in httpserver::webserver::finalize_answer(MHD_Connection*, httpserver::details::modded_request*, char const*)\r\n==================\r\n- Time spent during \"thread_safety\": 10702.4 ms\r\n==================\r\n```\r\n\r\n\r\n**Reproduces how often:** 100%\r\n\r\n### Versions\r\n\r\n* OS version : Linux 5f8a17221539 5.19.0-46-generic #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2 x86_64 GNU/Linux\r\n* libhttpserver version: master (d249ba682441dbb979146482aff01a7073ed165a) compiled locally\r\n* libmicrohttpd version: 0.9.64 compiled locally\r\n","author":{"url":"https://github.com/FlorianChevassu","@type":"Person","name":"FlorianChevassu"},"datePublished":"2023-07-24T15:26:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/329/libhttpserver/issues/329"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f12ce81c-e4dd-5c88-395e-57f38bc3836f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCA82:42D51:13F8F87:1ABBCB2:6964A285
html-safe-noncee0fa829742df292e5d059163dd3d3ac513d7b9ae1651c79b8f22d7c153bff550
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTgyOjQyRDUxOjEzRjhGODc6MUFCQkNCMjo2OTY0QTI4NSIsInZpc2l0b3JfaWQiOiIyMTgxODg2MTkxNzgwMjc0ODIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd8d26c6bd66051de05e5d3f2a1a591ca3caffcbf9d7b6dd8d5a3b75b67334aaf
hovercard-subject-tagissue:1818652170
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/etr/libhttpserver/329/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7b0f7867ea74ad608c9a34996ec2d3794ce7b54ad203e703e18e757a53589487/etr/libhttpserver/issues/329
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7b0f7867ea74ad608c9a34996ec2d3794ce7b54ad203e703e18e757a53589487/etr/libhttpserver/issues/329
og:image:altPrerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues Description T...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameFlorianChevassu
hostnamegithub.com
expected-hostnamegithub.com
Nonebaa7d9900fdf7b27d604f36887af878d569cfbdcf97126832a5f4f0caf0c6ba5
turbo-cache-controlno-preview
go-importgithub.com/etr/libhttpserver git https://github.com/etr/libhttpserver.git
octolytics-dimension-user_id1201536
octolytics-dimension-user_loginetr
octolytics-dimension-repository_id3416891
octolytics-dimension-repository_nwoetr/libhttpserver
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3416891
octolytics-dimension-repository_network_root_nwoetr/libhttpserver
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release842eff1d11f899d02b6b3b98fa3ea4860e64b34e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/etr/libhttpserver/issues/329#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fetr%2Flibhttpserver%2Fissues%2F329
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fetr%2Flibhttpserver%2Fissues%2F329
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=etr%2Flibhttpserver
Reloadhttps://github.com/etr/libhttpserver/issues/329
Reloadhttps://github.com/etr/libhttpserver/issues/329
Reloadhttps://github.com/etr/libhttpserver/issues/329
etr https://github.com/etr
libhttpserverhttps://github.com/etr/libhttpserver
Notifications https://github.com/login?return_to=%2Fetr%2Flibhttpserver
Fork 191 https://github.com/login?return_to=%2Fetr%2Flibhttpserver
Star 942 https://github.com/login?return_to=%2Fetr%2Flibhttpserver
Code https://github.com/etr/libhttpserver
Issues 40 https://github.com/etr/libhttpserver/issues
Pull requests 11 https://github.com/etr/libhttpserver/pulls
Actions https://github.com/etr/libhttpserver/actions
Projects 0 https://github.com/etr/libhttpserver/projects
Wiki https://github.com/etr/libhttpserver/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/etr/libhttpserver/security
Please reload this pagehttps://github.com/etr/libhttpserver/issues/329
Insights https://github.com/etr/libhttpserver/pulse
Code https://github.com/etr/libhttpserver
Issues https://github.com/etr/libhttpserver/issues
Pull requests https://github.com/etr/libhttpserver/pulls
Actions https://github.com/etr/libhttpserver/actions
Projects https://github.com/etr/libhttpserver/projects
Wiki https://github.com/etr/libhttpserver/wiki
Security https://github.com/etr/libhttpserver/security
Insights https://github.com/etr/libhttpserver/pulse
New issuehttps://github.com/login?return_to=https://github.com/etr/libhttpserver/issues/329
New issuehttps://github.com/login?return_to=https://github.com/etr/libhttpserver/issues/329
[BUG] Data raceshttps://github.com/etr/libhttpserver/issues/329#top
https://github.com/etr
bugConfirmed bugs or reports that are very likely to be bugs.https://github.com/etr/libhttpserver/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/FlorianChevassu
https://github.com/FlorianChevassu
FlorianChevassuhttps://github.com/FlorianChevassu
on Jul 24, 2023https://github.com/etr/libhttpserver/issues/329#issue-1818652170
https://github.com/search?l=&q=repo%3Aetr%2Flibhttpserver&type=Issueshttps://github.com/search?l=&q=repo%3Aetr%2Flibhttpserver&type=Issues
Cannot register multiple endpoints #47https://github.com/etr/libhttpserver/issues/47
d249ba6https://github.com/etr/libhttpserver/commit/d249ba682441dbb979146482aff01a7073ed165a
etrhttps://github.com/etr
bugConfirmed bugs or reports that are very likely to be bugs.https://github.com/etr/libhttpserver/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.