git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
To: Jiri Sevcik <jsevcik14@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Fwd: git-remote-fd problem
Date: Mon, 29 Dec 2014 21:36:51 +0200	[thread overview]
Message-ID: <20141229193651.GA16875@LK-Perkele-VII> (raw)
In-Reply-To: <CAOP4-933YWoJ8QO0ZY2KG1cgtZ6jAR8oL4L9hw_0CcicDnepnQ@mail.gmail.com>

On Mon, Dec 29, 2014 at 10:47:58AM +0100, Jiri Sevcik wrote:
> > 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.

> 
>     #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

      reply	other threads:[~2014-12-29 19:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-10 13:29 git-remote-fd problem Jiri Sevcik
2014-09-10 14:47 ` Ilari Liusvaara
     [not found]   ` <CAOP4-92U+oFJJw38LWNmTqPtKMT=MDq0Ay9FiaGV5je77aUNpg@mail.gmail.com>
2014-12-29  9:47     ` Fwd: " Jiri Sevcik
2014-12-29 19:36       ` Ilari Liusvaara [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141229193651.GA16875@LK-Perkele-VII \
    --to=ilari.liusvaara@elisanet.fi \
    --cc=git@vger.kernel.org \
    --cc=jsevcik14@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).