git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-remote-fd problem

From
JSJiri Sevcik <jsevcik14@gmail.com>
Date
Sep 10, 2014, 13:29 UTC
Message-ID
<CAOP4-939uAP2Tgofz01F40_Eb0F8GxBsU49HxNvAiyBCW6H08w@mail.gmail.com>

Hi! I have problem with using git-remote-fd function. I create two local pipes for communication for locally running process git pull. Then I start git-upload-pack on remote side (this process is started in different part of my code and it works correctly). Communication runs successfully and when remote side finish, I want to close local pipes to finish local process. I call close function to all of these pipes, but unfortunatelly local process doesnt finish (in this moment transfered data aresaved in /.git/object/pack folder in .pack files) and hanging on. But if I kill child of this local process, downloaded files are unpacked and files are created sucessfully. I think this way is not so correct. Can someone help me and tell me what am I doing wrong? Thank You. Code is in an attachement (its part of big system).

    #create local pipes for cimmunication
    local_r, local_w = os.pipe()
    remote_r, remote_w = os.pipe()
    #start local git process
    client_process = subprocess.Popen("/usr/bin/git pull fd::{0},{1}".format(remote_r, local_w,), shell=True)
    
    #start git process on remote side 
    remoteGit = proc.runDaemon("sudo git-upload-pack /tmp/testGit")
    #set
    epoll = select.epoll()
    epoll.register(local_r, select.EPOLLIN)
    #register from remote side
    epoll.register(proc.fd, select.EPOLLIN)
    while True:
        events = epoll.poll(1)
        for fd, event in events:
            if fd == local_r:
                #event on local process
                if event & select.EPOLLIN:
                    rd = os.read(local_r, 5000)
                    if rd:
                        #write data to remote side
                        remoteGit.writeToChannel(rd)
                    else:
                        proc.writeError("Local socket write error")
                        client_process.kill()
                        return 1
                else:
                    proc.writeError("Local socket error")
                    client_process.kill()
                    return 1
            else:
                if event & select.EPOLLIN:
                    #get all data from remote side
                    data = remoteGit.getAll()
                    remoteGit.stderrWrite()
                    if not data:
                        #remote side finished - close local pipes - local process wouldnt finish 
                        os.close(local_r) 
                        os.close(local_w)
                        os.close(remote_r)
                        os.close(remote_w)
                        #get local process pid and kill his child to finish git-remote-fd
                        gitPid = psutil.Process(client_process.pid).children()[0].pid
                        os.kill(gitPid, signal.SIGTERM)
                        return 0
                    want = len(data)
                    writed = 0
                    offset = 0
                    while(writed != want):
                        #write data from remote side to local process
                        wr = os.write(remote_w, data[offset:])
                        if(wr < 0):
                            proc.writeError("Local socket write error")
                            return 1
                        writed += wr
                        offset += wr
                else:
                    proc.writeError("Remote socket error")
                    client_process.kill()
                    return -1
Next: Ilari Liusvaara
Message 1 of 4 in “git-remote-fd problem”
  1. Jiri SevcikSep 10, 2014
  2. Ilari LiusvaaraSep 10, 2014
  3. Fwd: git-remote-fd problemJiri Sevcik, Dec 29, 2014
  4. Ilari LiusvaaraDec 29, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.