Skip to content

Commit 48f7556

Browse files
Toshiyuki Ogawatoshiyuki-ogawa
authored andcommitted
Run git-daemon on windows without closing socket immediately.
git client had exit with 'read error' some time, if connected git-daemon on windows. The cause was that git-daemon close socket immediately. I fixed this problem. Here is detail the explanation. https://github.com/toshiyuki-ogawa/msysgit/wiki/A-consideration-of--'fatal:-read-error-(invalid-argument)' Signed-off-by: Toshiyuki Ogawa <[email protected]>
1 parent 694fb72 commit 48f7556

31 files changed

+2213
-63
lines changed

Documentation/git-close-socket.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
git-close-socket(1)
2+
===================
3+
4+
NAME
5+
----
6+
git-close-socket - Close socket like Linux.
7+
8+
9+
SYNOPSIS
10+
--------
11+
[verse]
12+
'git close-socket'
13+
14+
DESCRIPTION
15+
-----------
16+
17+
Emulate to close socket as Linux. Some system, especialy windows, will close
18+
soket immediately. In such system git daemon will not communicate some git
19+
clients well.
20+
This command resovle the problem. Command will sleep some secondes and exit.
21+
Sleep seconds is specified below order.
22+
23+
Windows::
24+
1. 'git-config --int win.sock.time.wait'
25+
2. half of registry value 'HKLM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\TcpTimedWaitDelay'
26+
3. 240
27+
28+
29+
SEE ALSO
30+
--------
31+
http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-4.html#ss4.2
32+
http://msdn.microsoft.com/en-us/library/windows/desktop/ms737582.asp
33+
linkgit:git-config[1]
34+
35+
GIT
36+
---
37+
Part of the linkgit:git[1] suite

Documentation/git-pack-objects.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ So does `git bundle` (see linkgit:git-bundle[1]) when it creates a bundle.
224224
With this option, parents that are hidden by grafts are packed
225225
nevertheless.
226226

227+
--shutdown-out-socket::
228+
On exit, shutdown outgoing socket if outgoing file descript is
229+
socket.
230+
227231
SEE ALSO
228232
--------
229233
linkgit:git-rev-list[1]

Documentation/git-upload-pack.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-upload-pack - Send objects packed back to git-fetch-pack
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git-upload-pack' [--strict] [--timeout=<n>] <directory>
12+
'git-upload-pack' [--strict] [--timeout=<n>] [--shutdown-out-soket] <directory>
1313

1414
DESCRIPTION
1515
-----------
@@ -31,6 +31,9 @@ OPTIONS
3131
--timeout=<n>::
3232
Interrupt transfer after <n> seconds of inactivity.
3333

34+
--shutdown-out-socket::
35+
Shutdown outgoing file descripter, if file descripter is socket.
36+
3437
<directory>::
3538
The repository to sync from.
3639

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ PROGRAM_OBJS += shell.o
504504
PROGRAM_OBJS += show-index.o
505505
PROGRAM_OBJS += upload-pack.o
506506
PROGRAM_OBJS += remote-testsvn.o
507+
PROGRAM_OBJS += close-socket.o
507508

508509
# Binary suffix, set to .exe for Windows builds
509510
X =
@@ -532,7 +533,7 @@ TEST_PROGRAMS_NEED_X += test-sigchain
532533
TEST_PROGRAMS_NEED_X += test-string-list
533534
TEST_PROGRAMS_NEED_X += test-subprocess
534535
TEST_PROGRAMS_NEED_X += test-svn-fe
535-
536+
TEST_PROGRAMS_NEED_X += test-env-utils
536537
TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
537538

538539
# List built-in command $C whose implementation cmd_$C() is not in
@@ -630,6 +631,9 @@ LIB_H += compat/terminal.h
630631
LIB_H += compat/win32/dirent.h
631632
LIB_H += compat/win32/pthread.h
632633
LIB_H += compat/win32/syslog.h
634+
LIB_H += compat/winsock-proc.h
635+
LIB_H += compat/winsock-utils.h
636+
LIB_H += compat/win-fd.h
633637
LIB_H += connected.h
634638
LIB_H += convert.h
635639
LIB_H += credential.h
@@ -639,6 +643,7 @@ LIB_H += delta.h
639643
LIB_H += diff.h
640644
LIB_H += diffcore.h
641645
LIB_H += dir.h
646+
LIB_H += evn-utils.h
642647
LIB_H += exec_cmd.h
643648
LIB_H += fetch-pack.h
644649
LIB_H += fmt-merge-msg.h
@@ -688,6 +693,7 @@ LIB_H += sha1-lookup.h
688693
LIB_H += shortlog.h
689694
LIB_H += sideband.h
690695
LIB_H += sigchain.h
696+
LIB_H += socket-utils.h
691697
LIB_H += strbuf.h
692698
LIB_H += streaming.h
693699
LIB_H += string-list.h
@@ -753,6 +759,7 @@ LIB_OBJS += dir.o
753759
LIB_OBJS += editor.o
754760
LIB_OBJS += entry.o
755761
LIB_OBJS += environment.o
762+
LIB_OBJS += env-utils.o
756763
LIB_OBJS += exec_cmd.o
757764
LIB_OBJS += fetch-pack.o
758765
LIB_OBJS += fsck.o
@@ -818,6 +825,7 @@ LIB_OBJS += sha1_name.o
818825
LIB_OBJS += shallow.o
819826
LIB_OBJS += sideband.o
820827
LIB_OBJS += sigchain.o
828+
LIB_OBJS += socket-utils.o
821829
LIB_OBJS += strbuf.o
822830
LIB_OBJS += streaming.o
823831
LIB_OBJS += string-list.o
@@ -1292,7 +1300,7 @@ ifeq ($(uname_S),Windows)
12921300
BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
12931301
COMPAT_OBJS = compat/msvc.o compat/winansi.o \
12941302
compat/win32/pthread.o compat/win32/syslog.o \
1295-
compat/win32/dirent.o
1303+
compat/win32/dirent.o
12961304
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
12971305
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE
12981306
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib
@@ -1441,12 +1449,17 @@ ifneq (,$(findstring MINGW,$(uname_S)))
14411449
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
14421450
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
14431451
compat/win32/pthread.o compat/win32/syslog.o \
1444-
compat/win32/dirent.o
1452+
compat/win32/dirent.o \
1453+
compat/winsock-proc.o \
1454+
compat/win-fd.o \
1455+
compat/winsock-utils.o
14451456
BASIC_LDFLAGS += -Wl,--large-address-aware
14461457
EXTLIBS += -lws2_32
14471458
GITLIBS += git.res
14481459
PTHREAD_LIBS =
14491460
RC = windres -O coff
1461+
TEST_PROGRAMS_NEED_X += test-win-fd
1462+
TEST_PROGRAMS_NEED_X += test-winsock-utils
14501463
X = .exe
14511464
SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
14521465
ifneq (,$(wildcard ../THIS_IS_MSYSGIT))

builtin/pack-objects.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "refs.h"
1919
#include "streaming.h"
2020
#include "thread-utils.h"
21-
21+
#include "socket-utils.h"
2222
static const char *pack_usage[] = {
2323
N_("git pack-objects --stdout [options...] [< ref-list | < object-list]"),
2424
N_("git pack-objects [options...] base-name [< ref-list | < object-list]"),
@@ -811,7 +811,6 @@ static void write_pack_file(void)
811811
die("wrote %"PRIu32" objects while expecting %"PRIu32,
812812
written, nr_result);
813813
}
814-
815814
static int locate_object_entry_hash(const unsigned char *sha1)
816815
{
817816
int i;
@@ -2433,7 +2432,6 @@ static int option_parse_ulong(const struct option *opt,
24332432
#define OPT_ULONG(s, l, v, h) \
24342433
{ OPTION_CALLBACK, (s), (l), (v), "n", (h), \
24352434
PARSE_OPT_NONEG, option_parse_ulong }
2436-
24372435
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
24382436
{
24392437
int use_internal_rev_list = 0;
@@ -2598,5 +2596,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
25982596
fprintf(stderr, "Total %"PRIu32" (delta %"PRIu32"),"
25992597
" reused %"PRIu32" (delta %"PRIu32")\n",
26002598
written, written_delta, reused, reused_delta);
2599+
#ifdef EMULATE_TIME_WAIT_SOCKET
2600+
2601+
2602+
if (pack_to_stdout && is_socket(1)) {
2603+
set_socket_to_time_wait(1, 1);
2604+
}
2605+
#endif
26012606
return 0;
26022607
}

close-socket.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "cache.h"
2+
#include <time.h>
3+
#ifdef WIN32
4+
#include "winsock-utils.h"
5+
#endif
6+
7+
#ifdef EMULATE_TIME_WAIT_SOCKET
8+
#ifdef WIN32
9+
static int wait_for_time_out(void)
10+
{
11+
time_t start_time;
12+
time_t wait_time;
13+
start_time = time(NULL);
14+
wait_time = get_socket_time_wait();
15+
while (time(NULL) - start_time < wait_time) {
16+
sleep(1);
17+
}
18+
return 0;
19+
}
20+
#endif
21+
#else
22+
static int wait_for_time_out(void)
23+
{
24+
return 0;
25+
}
26+
#endif
27+
int main(int argc, char** argv)
28+
{
29+
int result;
30+
31+
result = wait_for_time_out();
32+
return result;
33+
}

compat/mingw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
static const int delay[] = { 0, 1, 10, 20, 40 };
1010
unsigned int _CRT_fmode = _O_BINARY;
1111

12+
1213
int err_win_to_posix(DWORD winerr)
1314
{
1415
int error = ENOSYS;
@@ -1471,6 +1472,7 @@ static void socket_cleanup(void)
14711472
ipv6_getnameinfo = getnameinfo_stub;
14721473
}
14731474

1475+
14741476
static void ensure_socket_initialization(void)
14751477
{
14761478
WSADATA wsa;
@@ -1515,6 +1517,9 @@ static void ensure_socket_initialization(void)
15151517
atexit(socket_cleanup);
15161518
initialized = 1;
15171519
}
1520+
void mingw_ensure_socket_initialization(void) {
1521+
ensure_socket_initialization();
1522+
}
15181523

15191524
#undef gethostname
15201525
int mingw_gethostname(char *name, int namelen)

compat/mingw.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,7 @@ extern int err_win_to_posix(DWORD winerr);
467467

468468
extern const char *get_windows_home_directory();
469469
#define get_home_directory() get_windows_home_directory()
470+
471+
#define EMULATE_TIME_WAIT_SOCKET
472+
extern void mingw_ensure_socket_initialization();
473+

0 commit comments

Comments
 (0)