Skip to content

Commit

Permalink
mediasoup-worker prebuild: Fallback to local building if fetched bina…
Browse files Browse the repository at this point in the history
…ry doesn't run on current host (#1090)
  • Loading branch information
ibc committed May 26, 2023
1 parent cf66888 commit a30d27d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


### Next

* mediasoup-worker prebuild: Fallback to local building if fetched binary doesn't run on current host ([PR #1090](https://github.com/versatica/mediasoup/pull/1090)).


### 3.12.0

* Automate and publish prebuilt `mediasoup-worker` binaries ([PR #1087](https://github.com/versatica/mediasoup/pull/1087), thanks to @barlock for his work in ([PR #1083](https://github.com/versatica/mediasoup/pull/1083)).
Expand Down
49 changes: 40 additions & 9 deletions npm-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async function run()
executeCmd(`git push origin v${MAYOR_VERSION}`);
executeCmd(`git push origin '${PKG.version}'`);

logInfo('creating release in GitHub');
logInfo('creating release in GitHub');

await octokit.repos.createRelease(
{
Expand Down Expand Up @@ -529,16 +529,47 @@ async function downloadPrebuiltWorker()
{
// Give execution permission to the binary.
fs.chmodSync(WORKER_RELEASE_BIN_PATH, 0o775);

resolve(true);
}
catch (error)
{
logError(
`downloadPrebuiltWorker() | failed to download mediasoup-worker prebuilt binary: ${error}`
);
logWarn(`downloadPrebuiltWorker() | failed to give execution permissions to the mediasoup-worker prebuilt binary: ${error}`);
}

// Let's confirm that the fetched mediasoup-worker prebuit binary does
// run in current host. This is to prevent weird issues related to
// different versions of libc in the system and so on.
// So run mediasoup-worker without the required MEDIASOUP_VERSION env and
// expect exit code 41 (see main.cpp).

logInfo(
'downloadPrebuiltWorker() | checking fetched mediasoup-worker prebuilt binary in current host'
);

resolve(false);
try
{
execSync(`${WORKER_RELEASE_BIN_PATH}`, { stdio: [ 'ignore', 'ignore', 'ignore' ] });
}
catch (error)
{
if (error.status === 41)
{
resolve(true);
}
else
{
logError(
`downloadPrebuiltWorker() | fetched mediasoup-worker prebuilt binary fails to run in this host [status:${error.status}]`
);

try
{
fs.unlinkSync(WORKER_RELEASE_BIN_PATH);
}
catch (error2)
{}

resolve(false);
}
}
})
.on('error', (error) =>
Expand All @@ -563,7 +594,7 @@ async function uploadMacArmPrebuiltWorker()

const octokit = getOctokit();

logInfo('uploadMacArmPrebuiltWorker() | getting release info');
logInfo('uploadMacArmPrebuiltWorker() | getting release info');

const release = await octokit.rest.repos.getReleaseByTag(
{
Expand All @@ -572,7 +603,7 @@ async function uploadMacArmPrebuiltWorker()
tag : PKG.version
});

logInfo('uploadMacArmPrebuiltWorker() | uploading release asset');
logInfo('uploadMacArmPrebuiltWorker() | uploading release asset');

await octokit.rest.repos.uploadReleaseAsset(
{
Expand Down
12 changes: 8 additions & 4 deletions worker/src/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ extern "C" int mediasoup_worker_run(
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();

return 1;
// 40 is a custom exit code to notify "unknown error" to the Node library.
return 40;
}

try
Expand All @@ -99,7 +100,8 @@ extern "C" int mediasoup_worker_run(
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();

return 1;
// 40 is a custom exit code to notify "unknown error" to the Node library.
return 40;
}

// Initialize the Logger.
Expand Down Expand Up @@ -130,7 +132,8 @@ extern "C" int mediasoup_worker_run(
DepLibUV::RunLoop();
DepLibUV::ClassDestroy();

return 1;
// 40 is a custom exit code to notify "unknown error" to the Node library.
return 40;
}

MS_DEBUG_TAG(info, "starting mediasoup-worker process [version:%s]", version);
Expand Down Expand Up @@ -193,7 +196,8 @@ extern "C" int mediasoup_worker_run(
{
MS_ERROR_STD("failure exit: %s", error.what());

return 1;
// 40 is a custom exit code to notify "unknown error" to the Node library.
return 40;
}
}

Expand Down
13 changes: 3 additions & 10 deletions worker/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ int main(int argc, char* argv[])
{
MS_ERROR_STD("you don't seem to be my real father!");

std::_Exit(EXIT_FAILURE);
// 41 is a custom exit code to notify about "missing MEDIASOUP_VERSION" env.
std::_Exit(41);
}

const std::string version = std::getenv("MEDIASOUP_VERSION");
Expand All @@ -40,13 +41,5 @@ int main(int argc, char* argv[])
nullptr,
nullptr);

switch (statusCode)
{
case 0:
std::_Exit(EXIT_SUCCESS);
case 1:
std::_Exit(EXIT_FAILURE);
case 42:
std::_Exit(42);
}
std::_Exit(statusCode);
}

0 comments on commit a30d27d

Please sign in to comment.