Skip to content

YQ-2790 fixed uncaught exception in TS3FileWriteActor #1242

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

Merged
Merged
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
42 changes: 35 additions & 7 deletions ydb/library/yql/providers/s3/actors/yql_s3_write_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
void Bootstrap(const TActorId& parentId) {
ParentId = parentId;
LOG_D("TS3FileWriteActor", "Bootstrap by " << ParentId << " for Key: [" << Key << "], Url: [" << Url << "], request id: [" << RequestId << "]");
auto authInfo = Credentials.GetAuthInfo();
try {
BeginPartsUpload(Credentials.GetAuthInfo());
} catch (...) {
FailOnException();
}
}

void BeginPartsUpload(const TS3Credentials::TAuthInfo& authInfo) {
if (DirtyWrite && Parts->IsSealed() && Parts->Size() <= 1) {
Become(&TS3FileWriteActor::SinglepartWorkingStateFunc);
Become(&TS3FileWriteActor::StateFuncWrapper<&TS3FileWriteActor::SinglepartWorkingStateFunc>);
const size_t size = Max<size_t>(Parts->Volume(), 1);
InFlight += size;
SentSize += size;
Expand All @@ -168,7 +175,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
true,
RetryPolicy);
} else {
Become(&TS3FileWriteActor::MultipartInitialStateFunc);
Become(&TS3FileWriteActor::StateFuncWrapper<&TS3FileWriteActor::MultipartInitialStateFunc>);
Gateway->Upload(Url + "?uploads",
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), {}, authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
0,
Expand All @@ -186,7 +193,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {

void PassAway() override {
if (InFlight || !Parts->Empty()) {
AbortMultipartUpload();
SafeAbortMultipartUpload();
LOG_W("TS3FileWriteActor", "PassAway: but NOT finished, InFlight: " << InFlight << ", Parts: " << Parts->Size() << ", Sealed: " << Parts->IsSealed() << ", request id: [" << RequestId << "]");
} else {
LOG_D("TS3FileWriteActor", "PassAway: request id: [" << RequestId << "]");
Expand Down Expand Up @@ -236,6 +243,15 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
return InFlight + Parts->Volume();
}
private:
template <void (TS3FileWriteActor::* DelegatedStateFunc)(STFUNC_SIG)>
STFUNC(StateFuncWrapper) {
try {
(this->*DelegatedStateFunc)(ev);
} catch (...) {
FailOnException();
}
}

STRICT_STFUNC(MultipartInitialStateFunc,
hFunc(TEvPrivate::TEvUploadStarted, Handle);
)
Expand Down Expand Up @@ -347,7 +363,7 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {

void Handle(TEvPrivate::TEvUploadStarted::TPtr& result) {
UploadId = result->Get()->UploadId;
Become(&TS3FileWriteActor::MultipartWorkingStateFunc);
Become(&TS3FileWriteActor::StateFuncWrapper<&TS3FileWriteActor::MultipartWorkingStateFunc>);
StartUploadParts();
}

Expand Down Expand Up @@ -404,22 +420,34 @@ class TS3FileWriteActor : public TActorBootstrapped<TS3FileWriteActor> {
RetryPolicy);
}

void AbortMultipartUpload() {
void SafeAbortMultipartUpload() {
try {
AbortMultipartUpload(Credentials.GetAuthInfo());
} catch (...) {
LOG_W("TS3FileWriteActor", "Failed to abort multipart upload, error: " << CurrentExceptionMessage());
}
}

void AbortMultipartUpload(const TS3Credentials::TAuthInfo& authInfo) {
// Try to abort multipart upload in case of unexpected termination.
// In case of error just logs warning.

if (!UploadId) {
return;
}

auto authInfo = Credentials.GetAuthInfo();
Gateway->Delete(Url + "?uploadId=" + UploadId,
IHTTPGateway::MakeYcHeaders(RequestId, authInfo.GetToken(), "application/xml", authInfo.GetAwsUserPwd(), authInfo.GetAwsSigV4()),
std::bind(&TS3FileWriteActor::OnMultipartUploadAbort, ActorSystem, SelfId(), TxId, RequestId, std::placeholders::_1),
RetryPolicy);
UploadId.clear();
}

void FailOnException() {
Send(ParentId, new TEvPrivate::TEvUploadError(NYql::NDqProto::StatusIds::BAD_REQUEST, CurrentExceptionMessage()));
SafeAbortMultipartUpload();
}

size_t InFlight = 0ULL;
size_t SentSize = 0ULL;

Expand Down
11 changes: 11 additions & 0 deletions ydb/tests/tools/kqprun/kqprun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,19 @@ void RunMain(int argc, const char* argv[]) {
RunScript(executionOptions, runnerOptions);
}

void KqprunTerminateHandler() {
NColorizer::TColors colors = NColorizer::AutoColors(Cerr);

Cerr << colors.Red() << "======= terminate() call stack ========" << colors.Default() << Endl;
FormatBackTrace(&Cerr);
Cerr << colors.Red() << "=======================================" << colors.Default() << Endl;

abort();
}

int main(int argc, const char* argv[]) {
std::set_terminate(KqprunTerminateHandler);

try {
RunMain(argc, argv);
} catch (...) {
Expand Down