docker-libreoffice-api icon indicating copy to clipboard operation
docker-libreoffice-api copied to clipboard

Binary URP bridge already disposed

Open gustawdaniel opened this issue 3 years ago • 0 comments

My docker compose

version: "3.7"
services:
  web:
    build: .
    ports:
      - "5000:5000"
    # DEBUG
    stdin_open: true
    tty: true
    depends_on:
      - "libreoffice"
    volumes:
      - "./app.py:/app.py"
    restart: unless-stopped
  libreoffice:
    image: "hdejager/libreoffice-api"
    ports:
      - "8100:8100"
    volumes:
      - "./kalkulator.xls:/kalkulator.xls"
    restart: unless-stopped

My Dockerfile

FROM python:3.9.2-buster
WORKDIR /

RUN DEBIAN_FRONTEND=noninteractive apt update && \
    DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends gcc python3-uno

RUN DEBIAN_FRONTEND=noninteractive apt autoremove -y && rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV LIBREOFFICE_HOSTNAME=libreoffice
ENV LIBREOFFICE_PORT=8100
ENV PYTHONPATH "/usr/lib/python3/dist-packages/"

ARG FLASK_PORT=5000
EXPOSE ${FLASK_PORT}
ENV FLASK_PORT=${FLASK_PORT}

ENTRYPOINT ["flask", "run"]

My app.py

import os
import pyoo
from flask import Flask, request
from flask_cors import CORS
from datetime import *
import random
from time import sleep
import traceback
from colorama import *
import sys

app = Flask(__name__)
CORS(app)

env = os.environ
libreofficeHostname = env["LIBREOFFICE_HOSTNAME"]
libreofficePort = int(env["LIBREOFFICE_PORT"])
libreoffice = pyoo.Desktop(libreofficeHostname, libreofficePort)

def captureException(e=None):
    if e is None:
        e = traceback.format_exc()
    print(f"{Fore.RED}Captured exception:\n{e}{Style.RESET_ALL}", file=sys.stderr)
    
...

@app.route('/calculate', methods=['POST'])
def calculate():
...

    while True:
        try:
            doc = libreoffice.open_spreadsheet("./kalkulator.xls", True, True)
            break
        except:
            captureException()
        print("Trying to open again....")
        sleep(5)
    sheet = doc.sheets[0]
    date = None

...

This projects works sometimes but sometimes not

Screenshot from 2021-06-11 08-18-17

red dots - dates of exceptions green dots - dates of working code

Exception means that all program hangs out and returns 500 on every next request until restart.

In logs there are following error:

Attaching to chf-api_web_1, chf-api_libreoffice_1                                                                                                                                    
web_1          |     doc = libreoffice.open_spreadsheet("./kalkulator.xls", True, True)                                                                                              
web_1          |   File "/usr/local/lib/python3.9/site-packages/pyoo.py", line 1889, in open_spreadsheet                                                                             
web_1          |     document = self._open_url(url, extra)                                                                                                                           
web_1          |   File "/usr/local/lib/python3.9/site-packages/pyoo.py", line 1895, in _open_url                                                                                    
web_1          |     return self._target.loadComponentFromURL(url, '_blank', 0, extra)                                                                                               
web_1          | pyoo.com.sun.star.lang.DisposedException: Binary URP bridge already disposed                                                                                        
web_1          |                                                                                                                                                                     
web_1          | Trying to open again....                                                                                                                                            
web_1          | Captured exception:                                                                                                                                                 
web_1          | Traceback (most recent call last):                                                                                                                                  
web_1          |   File "/app.py", line 106, in calculate                                                                                                                            
web_1          |     doc = libreoffice.open_spreadsheet("./kalkulator.xls", True, True)                                                                                              
web_1          |   File "/usr/local/lib/python3.9/site-packages/pyoo.py", line 1889, in open_spreadsheet                                                                             
web_1          |     document = self._open_url(url, extra)                                                                                                                           
web_1          |   File "/usr/local/lib/python3.9/site-packages/pyoo.py", line 1895, in _open_url                                                                                    
web_1          |     return self._target.loadComponentFromURL(url, '_blank', 0, extra)                                                                                               
web_1          | pyoo.com.sun.star.lang.DisposedException: Binary URP bridge already disposed                                                                                        
web_1          |                                                                                                                                                                     
web_1          | Trying to open again....                                                                                                                                            
web_1          | Captured exception:                                                                                                                                                 
web_1          | Traceback (most recent call last):                                                                                                                                  
web_1          |   File "/app.py", line 106, in calculate                                                                                                                            
web_1          |     doc = libreoffice.open_spreadsheet("./kalkulator.xls", True, True)                                                                                              
web_1          |   File "/usr/local/lib/python3.9/site-packages/pyoo.py", line 1889, in open_spreadsheet                                                                             
web_1          |     document = self._open_url(url, extra)                                                                                                                           
web_1          |   File "/usr/local/lib/python3.9/site-packages/pyoo.py", line 1895, in _open_url                                                                                    
web_1          |     return self._target.loadComponentFromURL(url, '_blank', 0, extra)                                                                                               
web_1          | pyoo.com.sun.star.lang.DisposedException: Binary URP bridge already disposed                                                                                        
web_1          |                                                                                                                                                                     
web_1          | Trying to open again....    

Where line 106 is:

doc = libreoffice.open_spreadsheet("./kalkulator.xls", True, True)

Similar discussions

https://github.com/unoconv/unoconv/issues/57 https://stackoverflow.com/questions/44071990/uno-error-binary-urp-bridge-disposed-during-call

Bug is hard to reproduce and occueres in random dates about 3-7 days after reboot. To fix I need use commands:

docker-compose down
docker-compose up

gustawdaniel avatar Jun 11 '21 06:06 gustawdaniel