Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/libc_include_fixes/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
extern "C" {
#endif

extern int* __errno_location(void)
#ifdef __THROW
__THROW
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW __THROW
#else
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW
#endif
;

extern int* __errno_location(void) USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW;

#undef USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW

#ifdef __cplusplus
}
Expand Down
10 changes: 7 additions & 3 deletions core/libc_include_fixes/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
extern "C" {
#endif

extern pthread_t pthread_self(void)
#ifdef __THROW
__THROW
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW __THROW
#else
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW
#endif
;

extern pthread_t pthread_self(void) USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW;

#undef USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW

#ifdef __cplusplus
}
Expand Down
9 changes: 6 additions & 3 deletions core/src/clients/dns/net_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,14 @@ class NetResolver::Impl {
}

void InitChannel() {
constexpr int kOptmask =
ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_DOMAINS |
constexpr int kSockStateCbOptmask =
#if ARES_VERSION < 0x011400
ARES_OPT_SOCK_STATE_CB |
ARES_OPT_SOCK_STATE_CB;
#else
0;
#endif
constexpr int kOptmask =
ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_DOMAINS | kSockStateCbOptmask |
ARES_OPT_LOOKUPS;
struct ares_options options {};
options.flags =
Expand Down
6 changes: 4 additions & 2 deletions core/src/dist_lock/dist_lock_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ UTEST_MT(LockedWorker, OkAfterFail, 3) {

// TODO: TAXICOMMON-1059
#if defined(__APPLE__) || defined(BSD)
UTEST_MT(LockedWorker, DISABLED_OkFailOk, 3) {
#define USERVER_IMPL_LOCKED_WORKER_OK_FAIL_OK DISABLED_OkFailOk
#else
UTEST_MT(LockedWorker, OkFailOk, 3) {
#define USERVER_IMPL_LOCKED_WORKER_OK_FAIL_OK OkFailOk
#endif

UTEST_MT(LockedWorker, USERVER_IMPL_LOCKED_WORKER_OK_FAIL_OK, 3) {
auto strategy = MakeMockStrategy();
DistLockWorkload work;
dist_lock::DistLockedWorker locked_worker(kWorkerName, [&] { work.Work(); }, strategy, MakeSettings());
Expand Down
6 changes: 4 additions & 2 deletions core/src/engine/ev/watcher/io_watcher_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
USERVER_NAMESPACE_BEGIN

#if defined(BSD) && !defined(__APPLE__)
UTEST(IoWatcher, DISABLED_DevNull) {
#define USERVER_IMPL_IO_WATCHER_DEV_NULL DISABLED_DevNull
#else
UTEST(IoWatcher, DevNull) {
#define USERVER_IMPL_IO_WATCHER_DEV_NULL DevNull
#endif

UTEST(IoWatcher, USERVER_IMPL_IO_WATCHER_DEV_NULL) {
LOG_DEBUG() << "Opening /dev/null";
engine::ev::Thread thread{"test_thread"};
engine::ev::ThreadControl thread_control(thread);
Expand Down
15 changes: 9 additions & 6 deletions core/src/engine/io/fd_control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ enum class ErrorMode {
kFatal, ///< break execute operation
};

constexpr bool IsRetryableIoError(int error_code) noexcept {
#if EWOULDBLOCK != EAGAIN
return error_code == EWOULDBLOCK || error_code == EAGAIN;
#else
return error_code == EWOULDBLOCK;
#endif
}

class FdControl;

class Direction final {
Expand Down Expand Up @@ -166,12 +174,7 @@ ErrorMode Direction::TryHandleError(
) {
if (error_code == EINTR) {
return ErrorMode::kProcessed;
} else if (error_code == EWOULDBLOCK
#if EWOULDBLOCK != EAGAIN
|| error_code == EAGAIN
#endif
)
{
} else if (IsRetryableIoError(error_code)) {
if (processed_bytes != 0 && mode != TransferMode::kWhole) {
return ErrorMode::kFatal;
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/engine/io/poller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ UTEST(Poller, ReadWriteMultipleTorture) {

// Disabled for mac, see https://st.yandex-team.ru/TAXICOMMON-4196
#ifdef BSD
UTEST(Poller, DISABLED_AwaitedEventsChange) {
#define USERVER_IMPL_POLLER_AWAITED_EVENTS_CHANGE DISABLED_AwaitedEventsChange
#else
UTEST(Poller, AwaitedEventsChange) {
#define USERVER_IMPL_POLLER_AWAITED_EVENTS_CHANGE AwaitedEventsChange
#endif
UTEST(Poller, USERVER_IMPL_POLLER_AWAITED_EVENTS_CHANGE) {
TcpListener listener;
auto socket_pair = listener.MakeSocketPair(engine::Deadline::FromDuration(utest::kMaxTestWaitTime));

Expand Down
59 changes: 35 additions & 24 deletions core/src/engine/io/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,41 @@ namespace {
constexpr size_t kMaxStackSizeVector = 32;

// MAC_COMPAT: does not accept flags in type
impl::FdControlHolder MakeSocket(AddrDomain domain, SocketType type) {
return impl::FdControl::Adopt(utils::CheckSyscallCustomException<IoSystemError>(
::socket(
static_cast<int>(domain),
constexpr int kSockNonblockFlag =
#ifdef SOCK_NONBLOCK
SOCK_NONBLOCK |
SOCK_NONBLOCK;
#else
0;
#endif

constexpr int kSockCloexecFlag =
#ifdef SOCK_CLOEXEC
SOCK_CLOEXEC |
SOCK_CLOEXEC;
#else
0;
#endif

// MAC_COMPAT: does not support MSG_NOSIGNAL
constexpr int kMsgNosignalFlag =
#ifdef MSG_NOSIGNAL
MSG_NOSIGNAL;
#else
0;
#endif

bool IsWouldBlock() noexcept {
#if EAGAIN != EWOULDBLOCK
return errno == EAGAIN || errno == EWOULDBLOCK;
#else
return errno == EAGAIN;
#endif
static_cast<int>(type),
}

impl::FdControlHolder MakeSocket(AddrDomain domain, SocketType type) {
return impl::FdControl::Adopt(utils::CheckSyscallCustomException<IoSystemError>(
::socket(
static_cast<int>(domain),
kSockNonblockFlag | kSockCloexecFlag | static_cast<int>(type),
/* protocol=*/0
),
"creating socket"
Expand Down Expand Up @@ -68,11 +92,7 @@ Sockaddr& MemoizeAddr(
fd,
buf,
len,
// MAC_COMPAT: does not support MSG_NOSIGNAL
#ifdef MSG_NOSIGNAL
MSG_NOSIGNAL |
#endif
0
kMsgNosignalFlag
);
}

Expand Down Expand Up @@ -106,11 +126,7 @@ class SendToWrapper {
fd,
buf,
len,
// MAC_COMPAT: does not support MSG_NOSIGNAL
#ifdef MSG_NOSIGNAL
MSG_NOSIGNAL |
#endif
0,
kMsgNosignalFlag,
dest_addr_.Data(),
dest_addr_.Size()
);
Expand Down Expand Up @@ -275,14 +291,9 @@ std::optional<size_t> Socket::RecvNoblock(void* buf, size_t len) {
const auto bytes_read = RecvWrapper(fd_control_->Fd(), buf, len);
if (bytes_read >= 0) {
return {bytes_read};
} else if (
#if EAGAIN != EWOULDBLOCK
EWOULDBLOCK == errno
#else
EAGAIN == errno
#endif
)
} else if (IsWouldBlock()) {
return {};
}

throw IoException("Attempt to RecvNoblock from closed socket");
}
Expand Down
18 changes: 8 additions & 10 deletions core/src/server/http/http_response_cookie_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

USERVER_NAMESPACE_BEGIN

#if defined(BSD) && !defined(__APPLE__)
#define USERVER_IMPL_HTTP_COOKIE_TIMEZONE "UTC; "
#else
#define USERVER_IMPL_HTTP_COOKIE_TIMEZONE "GMT; "
#endif

TEST(HttpCookie, Simple) {
server::http::Cookie cookie{"name1", "value1"};
EXPECT_EQ(cookie.ToString(), "name1=value1");
Expand All @@ -27,23 +33,15 @@ TEST(HttpCookie, Simple) {
const auto* const expected =
"name1=value1; Domain=domain.com; Path=/; Expires=Wed, 12 Jun 2019 "
"16:51:45 "
#if defined(BSD) && !defined(__APPLE__)
"UTC; "
#else
"GMT; "
#endif
USERVER_IMPL_HTTP_COOKIE_TIMEZONE
"Max-Age=3600; Secure; HttpOnly";
EXPECT_EQ(cookie.ToString(), expected);

cookie.SetSameSite("None");
const auto* const expected2 =
"name1=value1; Domain=domain.com; Path=/; Expires=Wed, 12 Jun 2019 "
"16:51:45 "
#if defined(BSD) && !defined(__APPLE__)
"UTC; "
#else
"GMT; "
#endif
USERVER_IMPL_HTTP_COOKIE_TIMEZONE
"Max-Age=3600; Secure; SameSite=None; HttpOnly";
EXPECT_EQ(cookie.ToString(), expected2);

Expand Down
9 changes: 5 additions & 4 deletions kafka/tests/producer_kafkatest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,14 @@ UTEST_F(ProducerTest, MessageTimeout) {
}
}

// Test flaps on GithubCI
#ifndef ARCADIA_ROOT
// Test flaps on GithubCI
GTEST_SKIP()
#define USERVER_IMPL_KAFKA_TRIGGER_FAILURES_RESULT GTEST_SKIP()
#else
FAIL()
#define USERVER_IMPL_KAFKA_TRIGGER_FAILURES_RESULT FAIL()
#endif
<< "Failed to trigger failures after " << kMaxRetries << " retries.";

USERVER_IMPL_KAFKA_TRIGGER_FAILURES_RESULT << "Failed to trigger failures after " << kMaxRetries << " retries.";
}

UTEST_F(ProducerTest, FullQueueBulk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <grpc-reflection/proto_server_reflection.hpp>

#include <stdexcept>
#include <string>
#include <unordered_set>
#include <vector>

Expand All @@ -36,6 +37,18 @@ USERVER_NAMESPACE_BEGIN

namespace grpc_reflection {

namespace {

auto ToDescriptorLookupName(std::string_view name) {
#if GOOGLE_PROTOBUF_VERSION >= 4022000
return name;
#else
return std::string{name};
#endif
}

} // namespace

ProtoServerReflection::ProtoServerReflection() : descriptor_pool_(grpc::protobuf::DescriptorPool::generated_pool()) {}

void ProtoServerReflection::AddService(std::string_view service) {
Expand Down Expand Up @@ -115,12 +128,9 @@ ProtoServerReflection::GetFileByName(std::string_view file_name, proto_reflectio
return ::grpc::Status::CANCELLED;
}

const grpc::protobuf::FileDescriptor* file_desc =
#if GOOGLE_PROTOBUF_VERSION >= 4022000
descriptor_pool_->FindFileByName(file_name);
#else
descriptor_pool_->FindFileByName(std::string{file_name});
#endif
const grpc::protobuf::FileDescriptor* file_desc = descriptor_pool_->FindFileByName(
ToDescriptorLookupName(file_name)
);
if (file_desc == nullptr) {
return ::grpc::Status(::grpc::StatusCode::NOT_FOUND, "File not found.");
}
Expand All @@ -137,11 +147,9 @@ ::grpc::Status ProtoServerReflection::GetFileContainingSymbol(
return ::grpc::Status::CANCELLED;
}

#if GOOGLE_PROTOBUF_VERSION >= 4022000
const grpc::protobuf::FileDescriptor* file_desc = descriptor_pool_->FindFileContainingSymbol(symbol);
#else
const grpc::protobuf::FileDescriptor* file_desc = descriptor_pool_->FindFileContainingSymbol(std::string{symbol});
#endif
const grpc::protobuf::FileDescriptor* file_desc = descriptor_pool_->FindFileContainingSymbol(
ToDescriptorLookupName(symbol)
);
if (file_desc == nullptr) {
return ::grpc::Status(::grpc::StatusCode::NOT_FOUND, "Symbol not found.");
}
Expand Down Expand Up @@ -181,11 +189,7 @@ ::grpc::Status ProtoServerReflection::GetAllExtensionNumbers(
return ::grpc::Status::CANCELLED;
}

#if GOOGLE_PROTOBUF_VERSION >= 4022000
const grpc::protobuf::Descriptor* desc = descriptor_pool_->FindMessageTypeByName(type);
#else
const grpc::protobuf::Descriptor* desc = descriptor_pool_->FindMessageTypeByName(std::string{type});
#endif
const grpc::protobuf::Descriptor* desc = descriptor_pool_->FindMessageTypeByName(ToDescriptorLookupName(type));
if (desc == nullptr) {
return ::grpc::Status(::grpc::StatusCode::NOT_FOUND, "Type not found.");
}
Expand Down
28 changes: 18 additions & 10 deletions mongo/src/storages/mongo/cdriver/pool_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ void HeartbeatFailed(const mongoc_apm_server_heartbeat_failed_t* event) {
HeartbeatFinished(stats);
}

bool HasReadableServer(const mongoc_topology_description_t* td, mongoc_read_prefs_t* prefs) {
#if MONGOC_CHECK_VERSION(1, 17, 0)
return mongoc_topology_description_has_readable_server(td, prefs);
#else
return mongoc_topology_description_has_readable_server(const_cast<mongoc_topology_description_t*>(td), prefs);
#endif
}

bool HasWritableServer(const mongoc_topology_description_t* td) {
#if MONGOC_CHECK_VERSION(1, 17, 0)
return mongoc_topology_description_has_writable_server(td);
#else
return mongoc_topology_description_has_writable_server(const_cast<mongoc_topology_description_t*>(td));
#endif
}

std::string CreateTopologyChangeMessage(const mongoc_apm_topology_changed_t* event) {
const mongoc_topology_description_t* prev_td = mongoc_apm_topology_changed_get_previous_description(event);
const mongoc_topology_description_t* new_td = mongoc_apm_topology_changed_get_new_description(event);
Expand Down Expand Up @@ -261,21 +277,13 @@ std::string CreateTopologyChangeMessage(const mongoc_apm_topology_changed_t* eve
mongoc_read_prefs_t* prefs = mongoc_read_prefs_new(MONGOC_READ_SECONDARY);
const utils::FastScopeGuard prefs_guard{[&prefs]() noexcept { mongoc_read_prefs_destroy(prefs); }};

#if MONGOC_CHECK_VERSION(1, 17, 0)
if (mongoc_topology_description_has_readable_server(new_td, prefs)) {
#else
if (mongoc_topology_description_has_readable_server(const_cast<mongoc_topology_description_t*>(new_td), prefs)) {
#endif
if (HasReadableServer(new_td, prefs)) {
topology_msg.append("\nSecondary AVAILABLE\n");
} else {
topology_msg.append("\nSecondary UNAVAILABLE\n");
}

#if MONGOC_CHECK_VERSION(1, 17, 0)
if (mongoc_topology_description_has_writable_server(new_td)) {
#else
if (mongoc_topology_description_has_writable_server(const_cast<mongoc_topology_description_t*>(new_td))) {
#endif
if (HasWritableServer(new_td)) {
topology_msg.append("Primary AVAILABLE");
} else {
topology_msg.append("Primary UNAVAILABLE");
Expand Down
Loading