summaryrefslogtreecommitdiff
path: root/python-ephemeral-port-reserve.spec
blob: 0a16bf8d7dbb6c8863f47594ac8e8b7654551acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
%global _empty_manifest_terminate_build 0
Name:		python-ephemeral-port-reserve
Version:	1.1.4
Release:	1
Summary:	Bind to an ephemeral port, force it into the TIME_WAIT state, and unbind it.
License:	MIT
URL:		https://github.com/Yelp/ephemeral-port-reserve/
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/ef/93/3f0b75f75f94227f67ccfe86f989415e40ac054dd67b55dfac7abdc0a2d2/ephemeral_port_reserve-1.1.4.tar.gz
BuildArch:	noarch


%description
# `ephemeral-port-reserve`
Sometimes you need a networked program to bind to a port that can't be hard-coded.
Generally this is when you want to run several of them in parallel; if they all
bind to port 8080, only one of them can succeed.

The usual solution is the "port 0 trick". If you bind to port 0, your kernel will
find some arbitrary high-numbered port that's unused and bind to that. Afterward
you can query the actual port that was bound to if you need to use the port number
elsewhere. However, there are cases where the port 0 trick won't work. For example,
mysqld takes port 0 to mean "the port configured in my.cnf". Docker can bind your
containers to port 0, but uses its own implementation to find a free port which
races and fails in the face of parallelism.

`ephemeral-port-reserve` provides an implementation of the port 0 trick which
is reliable and race-free. You can use it like so:

```!bash
PORT="$(ephemeral-port-reserve)"
docker run -p 127.0.0.1:$PORT:5000 registry:2
```


`ephemeral-port-reserve` is a utility to bind to an ephemeral port, force it into
the `TIME_WAIT` state, and unbind it.

This means that further ephemeral port alloctions won't pick this "reserved" port,
but subprocesses can still bind to it explicitly, given that they use `SO_REUSEADDR`.
By default on linux you have a grace period of 60 seconds to reuse this port.
To check your own particular value:

```!bash
$ cat /proc/sys/net/ipv4/tcp_fin_timeout
60
```

**NOTE:** By default, the port returned is *specifically* for `localhost`, aka `127.0.0.1`.
If you bind instead to `0.0.0.0`, you may encounter a port conflict. If you need to
bind to a non-localhost IP, you can pass it as the first argument.




%package -n python3-ephemeral-port-reserve
Summary:	Bind to an ephemeral port, force it into the TIME_WAIT state, and unbind it.
Provides:	python-ephemeral-port-reserve
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-ephemeral-port-reserve
# `ephemeral-port-reserve`
Sometimes you need a networked program to bind to a port that can't be hard-coded.
Generally this is when you want to run several of them in parallel; if they all
bind to port 8080, only one of them can succeed.

The usual solution is the "port 0 trick". If you bind to port 0, your kernel will
find some arbitrary high-numbered port that's unused and bind to that. Afterward
you can query the actual port that was bound to if you need to use the port number
elsewhere. However, there are cases where the port 0 trick won't work. For example,
mysqld takes port 0 to mean "the port configured in my.cnf". Docker can bind your
containers to port 0, but uses its own implementation to find a free port which
races and fails in the face of parallelism.

`ephemeral-port-reserve` provides an implementation of the port 0 trick which
is reliable and race-free. You can use it like so:

```!bash
PORT="$(ephemeral-port-reserve)"
docker run -p 127.0.0.1:$PORT:5000 registry:2
```


`ephemeral-port-reserve` is a utility to bind to an ephemeral port, force it into
the `TIME_WAIT` state, and unbind it.

This means that further ephemeral port alloctions won't pick this "reserved" port,
but subprocesses can still bind to it explicitly, given that they use `SO_REUSEADDR`.
By default on linux you have a grace period of 60 seconds to reuse this port.
To check your own particular value:

```!bash
$ cat /proc/sys/net/ipv4/tcp_fin_timeout
60
```

**NOTE:** By default, the port returned is *specifically* for `localhost`, aka `127.0.0.1`.
If you bind instead to `0.0.0.0`, you may encounter a port conflict. If you need to
bind to a non-localhost IP, you can pass it as the first argument.




%package help
Summary:	Development documents and examples for ephemeral-port-reserve
Provides:	python3-ephemeral-port-reserve-doc
%description help
# `ephemeral-port-reserve`
Sometimes you need a networked program to bind to a port that can't be hard-coded.
Generally this is when you want to run several of them in parallel; if they all
bind to port 8080, only one of them can succeed.

The usual solution is the "port 0 trick". If you bind to port 0, your kernel will
find some arbitrary high-numbered port that's unused and bind to that. Afterward
you can query the actual port that was bound to if you need to use the port number
elsewhere. However, there are cases where the port 0 trick won't work. For example,
mysqld takes port 0 to mean "the port configured in my.cnf". Docker can bind your
containers to port 0, but uses its own implementation to find a free port which
races and fails in the face of parallelism.

`ephemeral-port-reserve` provides an implementation of the port 0 trick which
is reliable and race-free. You can use it like so:

```!bash
PORT="$(ephemeral-port-reserve)"
docker run -p 127.0.0.1:$PORT:5000 registry:2
```


`ephemeral-port-reserve` is a utility to bind to an ephemeral port, force it into
the `TIME_WAIT` state, and unbind it.

This means that further ephemeral port alloctions won't pick this "reserved" port,
but subprocesses can still bind to it explicitly, given that they use `SO_REUSEADDR`.
By default on linux you have a grace period of 60 seconds to reuse this port.
To check your own particular value:

```!bash
$ cat /proc/sys/net/ipv4/tcp_fin_timeout
60
```

**NOTE:** By default, the port returned is *specifically* for `localhost`, aka `127.0.0.1`.
If you bind instead to `0.0.0.0`, you may encounter a port conflict. If you need to
bind to a non-localhost IP, you can pass it as the first argument.




%prep
%autosetup -n ephemeral-port-reserve-1.1.4

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-ephemeral-port-reserve -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Apr 25 2023 Python_Bot <Python_Bot@openeuler.org> - 1.1.4-1
- Package Spec generated