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

Re: Fwd: git-remote-fd problem

From
ILIlari Liusvaara <ilari.liusvaara@elisanet.fi>
Date
Dec 29, 2014, 19:36 UTC
Message-ID
<20141229193651.GA16875@LK-Perkele-VII>
In-Reply-To
<CAOP4-933YWoJ8QO0ZY2KG1cgtZ6jAR8oL4L9hw_0CcicDnepnQ@mail.gmail.com>
On Mon, Dec 29, 2014 at 10:47:58AM +0100, Jiri Sevcik wrote:
Show 14 quoted lines
> > The remote-fd expects the transport to pass half-closes. So you can't
> > close all at once.
> >
> > Let there be pipes W and R and transport connection C.
> >
> > - W-read should be closed after being passed to remote-fd.
> > - R-write should be closed after being passed to remote-fd.
> > - Upon receiving "no more data" from C, close W-write.
> > - Upon receiving EOF from R-read, close it and signal "no more data"
> >   to C.
> 
> Hi, I followed your advices, correctly close pipes but git clone still
> doesnt finish and hanging on.
> Code is in an attachement (its part of big system).
Few ideas:
- Check that git clone (and its subprocesses) don't inherit
w_pipe[0] (/proc/<pid>/fd on Linux might be handy). If they do, that
prevents this program from closing the pipe.
- Setting environment variable GIT_TRANSLOOP_DEBUG to 1 might make
  git spew lots of messages to stderr about reads, writes and closes.
Show 62 quoted lines
> 
>     #create pipes
>     w_pipe = os.pipe()
>     r_pipe = os.pipe()
> 
>     client_process = subprocess.Popen("/usr/bin/git clone fd::{0},{1} /tmp/gittest".format(r_pipe[0], w_pipe[1]), shell=True)
>     #closing pipes
>     os.close(r_pipe[0]) 
>     os.close(w_pipe[1])
> 
>     epoll = select.epoll()
>     epoll.register(w_pipe[0], select.EPOLLIN)
>     epoll.register(proc.fd, select.EPOLLIN)
> 
>     remoteGit = proc.runDaemon("git-upload-pack /tmp/testgit")
>     
>     while True:
>         events = epoll.poll(1)
> 
>         for fd, event in events:
>             if fd == w_pipe[0]:
>                 if event & select.EPOLLIN:
>                     rd = os.read(w_pipe[0], 10000)
>                     if rd:
>                         #write data to remove git server
>                         remoteGit.writeToChannel(rd)
>                     else:
>                         proc.writeError("Local socket write error")
>                         return 1
>                 else:
>                     proc.writeError("Local socket error")
>                     return 1
> 
>             elif fd == proc.fd:
>                 if event & select.EPOLLIN:
>                     #read data from remote git server
>                     data = remoteGit.getAll()
>                     remoteGit.stderrWrite()
> 
>                     if not data:
>                         #remote server send EOF, close local pipe
>                         #but git clone is still running
>                         os.close(r_pipe[1])
>                         return 0
>                     
>                     want = len(data)
> 
>                     writed = 0
>                     offset = 0
>                     
>                     while(writed != want):
>                         #write data from remote git server to local pipe
>                         wr = os.write(r_pipe[1], data[offset:])
> 
>                         if(wr < 0):
>                             return 1
> 
>                         writed += wr
>                         offset += wr
> 
>                 else:
>                     return -1              
-Ilari
Previous: Jiri Sevcik
Message 4 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.