【问题标题】:posix_fallocate() failed: Operation not permitted while opening .realm fileposix_fallocate() 失败:打开 .realm 文件时不允许操作
【发布时间】:2019-09-06 15:44:20
【问题描述】:

当我尝试在无服务器框架的 /tmp 目录中打开和下载 .realm 文件时出现以下错误。 {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: posix_fallocate() failed: Operation not allowed" }

Below is the code:

let realm = new Realm({path: '/tmp/custom.realm', schema: [schema1, schema2]});
realm.write(() => {
                console.log('completed==');
            });

【问题讨论】:

    标签: realm serverless


    【解决方案1】:

    编辑:这可能很快会在 Realm-Core 中得到修复:see issue 4957


    如果您在其他地方遇到此问题,这里有一个解决方法。

    这是由于 AWS Lambda 不支持 fallocatefallocate64 系统调用造成的。在这种情况下,亚马逊没有返回正确的错误代码,即EINVAL此文件系统不支持,亚马逊阻止了系统调用,以便它返回EPERM。 Realm-Core 的代码可以正确处理EINVAL 返回值,但会被系统调用返回的意外EPERM 弄糊涂。

    解决方案是在 lambda 中添加一个小型共享库作为层:在 Linux 机器上或在 lambda-ci Docker 映像中编译以下 C 文件:

    #include <errno.h>
    #include <fcntl.h>
    
    int posix_fallocate(int __fd, off_t __offset, off_t __len) {
        return EINVAL;
    }
    
    int posix_fallocate64(int __fd, off_t __offset, off_t __len) {
        return EINVAL;
    }
    
    1. 现在,把它编译成一个共享对象,比如

      gcc -shared fix.c -o fix.so
      
    2. 然后将其添加到 ZIP 文件的根目录中:

      zip layer.zip fix.so
      
    3. 从此 zip 创建一个新的 lambda 层

    4. 将 lambda 层添加到您的 lambda 函数中

    5. 最后通过将环境值LD_PRELOAD 和值/opt/fix.so 配置到您的Lambda 来加载共享对象。

    6. 享受吧。

    【讨论】:

    • 我们在运行wasm-ld时也遇到过类似的问题,这个解决方案也可以。
    猜你喜欢
    • 1970-01-01
    • 2023-02-07
    • 2012-06-19
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 2019-01-25
    相关资源
    最近更新 更多